Академический Документы
Профессиональный Документы
Культура Документы
Algorithm:
5gyweyeytve increases by 1 every time and perform step (b)
(b)
Store the natural numbers in the first row using A[r1][i] = k++
Step 7 :vesrvyhesy+1 to r2, where j increases by 1 every time and perform step (b)
(b)
Store the natural numbers in the last column using A[j][c2] = k++
Step 8 :e5yef
public rturturst
c2--;
r1++;
r2--;
}
/* Printing the Circular matrix */
System.out.println("The Circular Matrix is:");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(A[i][j]+ "\t");
}
System.out.println();
}
}
}rturtdyswruttu
Question:
A Palindrome is a word that may be read the same way in either direction.
Accept a sentence in UPPER CASE which is terminated by either . , ? or ! .
Each word of the sentence is separated by a single blank space.
Perform the following tasks:
(a) Display the count of palindromic words in the sentence.
MOM
DAD
NOON
Example 2
INPUT : NITIN ARORA USES LIRIL SOAP.
OUTPUT : NITIN ARORA LIRIL
NUMBER OF PALINDROMIC WORDS : 3
Example 3
INPUT : HOW ARE YOU?
OUTPUT : NO PALINDROMIC WORDS
Algorithm for main() method :
Step 1 :
Start of algotithm
Step 2 :
Step 3 :
Step 4 :
Create a StringTokenizer object str to extract tokens (words) from the sentence using space and other
the punctuation marks namely ., ?, !
Step 5 :
Count the number of tokens (words) and store it in an integer variable c. Also create a String array
word[ ] of size c
Step 6 :
Start a for loop from i = 0 to less than c and store the tokens of the sentence into the word [ ] array
Step 7 :
Step 8 :
Step 9 :
Call the function isPalin() as : ob.isPalin(word[i]). If the returned value is true then increase the count
variable and print the word.
Step 10 :
If count of palindromic words is not equal to zero, then print the value stored in the variable count
Step 11 :
Step 1 :
Step 2 :
Step 3 :
Declare and initialize a String variable rev= for storing the reverse of the String s
Step 4 :
Step 5 :
Extract characters from the end of the original string and add them to the variable rev
Step 6 :
false.
If the reverse word obtained (rev) is equal to the original String (s), then return true, otherwise return
Step 7 :
Similarly if you have more functions, then just write their algorithms in a similar fashion one after the
other.
import java.io.*;
import java.util.*;
class Palin_ISC2013
{
static BufferedReader br=new BufferedReader (new InputStreamReader (System.in));
boolean isPalin(String s)
{
int l=s.length();
String rev="";
if(count==0)
System.out.println("No Palindrome Words");
else
System.out.println("nNumber of Palindromic Words : "+count);
This is how you can write algorithms in your ISC Practical Examination. So, as you see, this is nothing
but step wise solution to the given program in English language.