Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 82

NAME: SHAKILA KHATOON

CLASS: XII (A)


ROLL: 20

Question 1:
Caesar Cipher is an encryption technique which is implemented as ROT13 (‘rotate by 13 places’). It is a
simple letter substitution cipher that replaces a letter with the letter 13 places after it in the alphabets, with
the other characters remaining unchanged.

Write a program to accept a plain text of length L, where L must be greater than 3 and less than 100.
Encrypt the text if valid as per the Caesar Cipher.
Test your program with the sample data and some random data:

Example 1
INPUT: Hello! How are you?
OUTPUT: The cipher text is:
Uryyb! Ubjnerlbh?
Example 2
INPUT: You
OUTPUT: INVALID LENGTH

ALGORITHM FOR main():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the text from the user.

Step 5: Finding the length of the sentence.

Step 6: If the length is less than or equal to 3 or greater than 100, printing invalid length.

Step 7: Creating string buffer object.

Step 8: Running a loop from 0 to the length of the sentence.

Step 8.1: Extracting each characters from the text.

Step 8.2: if the character extracted is between a to m, the characters position will be increased by 13
otherwise it is be reduced by 13.

Step 9: now, converting the characters to string.

Step 10: printing the cipher text.

Step 11: End.


SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
s String main To store the sentence by the user
len int main To store the length of the sentence
i int main Loop variable
c char main To extract characters from the sentence
Question 2:
Write a program in java to accept a number of sentence in a string array. Change the sentence of odd rows
with an encryption of two characters ahead of the original characters. Also change the sentence of the even
rows by storing the sentence in reverse order.

Sample input:
Enter no. of sentence: 3
Good morning.
Have a nice day!
It will rain today.
Sample output:
Encoded text:
Jrrg pruqlqj
day nice a Have
Lw zloo udlq wrgdb

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the number of sentences from the user.

Step 5: Creating array to accept the number of sentences.

Step 5: If the value of I modulus 2 is not equal to zero, then splitting the sentence into words with respect to
space and then iterating the loop backwards..Otherwise incrementing the value of j and then extracting the
characters and changing the characters.

Step 6: Printing the new text.

Step 7: End.

ALGORITHM FOR removePunc ():


Step 1: Start.

Step 2: Accepting the sentence from the console.

Step 3.1: Running a loop from 0 to the length of the sentence.

Step 3.2: Extracting each characters from the sentence.

Step 3.3: checking the space in the sentence and returning the new value.
Step 4: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOPE DESCRIPTION
NAME TYPES
i int main loop variable
n int main to store the number of sentences
str string main to store the sentence
words string main to split the sentence into words with respect to space
j int main to run a loop to print the array from end
ch char function To extract characters from the sentence

METHOD DESCRIPTION:
METHOD RETURN ARGUMENT PURPOSE
NAME TYPE LIST
removePunc String String sentence to remove punctuation from the sentence

Question 3:
Write a program in java to accept a string and display the new string after encoding.

Sample input:
Enter a sentence: Good morning.
Enter the shift value: 3
Sample output:
Encoded text:Jrrg pruqlqj

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Accepting the shifting value from the user.

Step 6: Creating string buffer object.

Step 7.1: Running a loop from 0 to the length of the sentence.

Step 7.2: Storing the duplicate of the shifting value.

Step 7.3: Extracting each character from the sentence.

Step 7.4: If the characters lies between A to Z, finding the ASCII values and storing the new character after
adding the shifting value.

Step 7.4: If the character lies between a to z, finding the ASCII values and storing the new character after
adding the shifting value.

Step 8: Converting the characters to string.

Step 9: Printing the encoded sentence.

Step 10: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOPE DESCRIPTION
NAME TYPES
s String main to accept the sentence from the user
shift int main to accept the shifting value
sh int main to store the copy of shifting value
ch char main to extract the characters from the sentence
v char main to extract the characters from the sentence
encode String main to convert into string
i int main loop variable

Question 4:
Write a program in java to accept an encoded string and display the decoded string.

Sample input:
Enter the sentence:
Kdyh d qlfh gdb!
Shift value: 3
Sample output:
Have a nice day!

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Accepting the shifting value from the user.

Step 6: Creating string buffer object.

Step 7.1: Running a loop from 0 to the length of the sentence.

Step 7.2: Storing the duplicate of the shifting value.

Step 7.3: Extracting each character from the sentence.

Step 7.4: If the characters lies between A to Z, finding the ASCII values and storing the new character after
adding the shifting value.

Step 7.4: If the characters lie between a to z, finding the ASCII values and storing the new character after
adding the shifting value.

Step 8: Printing the decoded sentence.

Step 9: End.
SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
sentence String main to accept the encoded sentence from the user
shift int main to accept the shifting value
decoded String main to store the decoded sentence
Pos int main to find the position of the character
newPos int main to store the new position
i int main loop variable
ch char main to extract characters from the sentence

Question 5:
Write a program that reads a sentence (the characters of the sentence may be capital or small or mixed) and
two positive integers and output the same sentence after replacing those words present at those given integer
places by the next character in a circular fashion according to the English Alphabets.

Example 1
Input Sentence: He has good Books.
Input Integers: 2, 4
Output Sentence: He ibt good Cpplt.
(i.e. word number 2 and 4 have been replaced by the next characters in a circular fashion)
Example 2
Input Sentence: Time and tide waits for none.
Input Integers: 3, 3
Output Sentence: Time and ujef waits for none.

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Accepting the two integer positions from the user.

Step 6: Splitting the sentence into words with respect to space.

Step 7: If the first position is equal to the second position, shifting the word and printing the words.

Step 8: End.

ALGORITHM FOR shift ():

Step 1: Start.

Step 2: Accepting the sentence from console.

Step 3.1: Running the loop till the length of the word.

Step 3.2: Extracting characters from the word.

Step 3.4: If the character is between A to Z, finding the position and getting the new word and vice versa.

Step 4: Printing the word.

Step 5: End.
SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOPE DESCRIPTION
NAME TYPES
sentence String main To accept the sentence from the user
pos1 int main To accept the first position from the user
pos2 int main To accept the second position from the user
words String main To split the sentence into words with respect to space
i int main Loop variable
newWord String function To store the new word
ch char function To extract characters from the user
pos int function To find the position of the character
newPos int function To store the new position

METHOD DESCRIPTION:
METHOD RETURN ARGUMENT PURPOSE
NAME TYPE LIST
shift String String word to return the new word

Question 6:
A simple encryption system uses a shifting process to hide a message. The value of the shift can be in the
range 1 to 26.
For example a shift of 7 means that A = U, B =V,C = W, etc. i e.
Text: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Code: U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
Fist an extra space is added to the end of the string. To make things little more difficult, spaces within the
original text are replaced with QQ before the text is encrypted. Double Q (QQ) was selected because no
English word ends in Q or contains QQ.
Additionally the coded message is printed in blocks of six characters separated by spaces. The last block
might not contain six characters. Write a program that takes the coded text (less than 100 characters), the
shift value and prints the decoded original text. Your program must reject any non-valid value for shift and
display an error message “INVALID SHIFT VALUE”. Assume all characters are upper case.

INPUT:
CODED TEXT: “RUIJGG EVGGBK SAGG”
SHIFT : 11
OUTPUT:
DECODED TEXT: BEST OF LUCK

ALGORITHM FOR main ():

Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Accepting the shifting value from the user.

Step 6: If the shifting value is less than 1 or greater than 26; printing invalid output.

Step 7: Splitting the sentence into words with respect to space.

Step 8: Running a loop till the words length and printing each word.

Step 9: Storing the j and j+1 characters.

Step 10: Checking if GG is present in the sentence or not, if true printing space instead.

Step 11: Now getting the ASCII values of each word and storing the char after shifting the values.

Step 12: Printing the sentence.

Step 13: End.


SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
sentence String main to accept the sentence from the user
shift int main to accept the shifting value
words String main to split the sentence into words with respect to space
i int main outer loop variable
j int main inner loop variable
word S main to extract each word
ch1 char main to extract the first character
ch2 char main to extract the second character
ascii1 int main to store the characters and round off
ascii2 int main to store the characters and round off
newChar1 char main to convert it into characters
newChar2 char main to convert it into characters

Question 7:
Write a program in java to accept two words and check whether they are anagram or not.
The words that are made with the combinations of the letters present in the original word are called
anagram.

Example: FLOW and WOLF are anagram words.

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the first word from the user.

Step 5: Accepting the second word from the user.

Step 6: Initializing Boolean value to true.

Step 7.1: Checking if the length of the first word is not equal to the length of the second word, printing not
an anagram.

Step 7.2.1: Else converting both the words to character array.

Step 7.2.2: Sorting the words into ascending order using array sorting function.

Step 7.2.3: If both the words are equal, printing the positive message otherwise printing negative message.

Step 8: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
s1 String main to store the first word from the user
s2 String main to store the second word from the user
b Boolean main to store the Boolean value as true
a1 char main to store the first word to character array
a2 char main to store the second word to character array

Question 8:
Write a program to accept a sentence which may be terminated by either’.’, ‘?’or’!’ only. The words may be
separated by more than one blank space and are in UPPER CASE.
(a) Find the number of words beginning and ending with a vowel.
(b) Place the words which begin and end with a vowel at the beginning, followed by the remaining words as
they occur in the sentence.
Test your program with the sample data and some random data:

Example 1
INPUT: ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.
OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL= 3
ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO

ALGORITHM:
Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Converting the sentence to uppercase.

Step 6: Storing the length of the sentence.

Step 7: Storing the last character of the array.

Step 8: If the last character ends with question mark, exclamation mark or full stop, storing the full sentence
except the marks in a variable.

Step 9: Splitting the sentence into words with respect to space.

Step 10: Initializing the counter variable to 0.

Step 11.1: Running a loop from 0 to the length of the word.

Step 11.2: Storing the length of the word.

Step 11.3: Storing the first and the last character.

Step 11.4: If the first and last characters are vowel, incrementing the counter variable and adding the word to
the sentence else adding the consonants.

Step 11.5: Adding the vowels and the consonants word to form a sentence.

Step 11.6: Printing the number of words beginning and ending with vowel and the new sentence.

Step 11.7: Else printing the invalid output.

Step 12: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
s String main to accept the sentence from the user
len int main to store the length of the sentence
ch char main to store the last character of the sentence
a String main to split the sentence with respect to space
vowel String main to store the vowels
consonant String main to store the consonants
count int main to count the number of vowels
i int main loop variable
temp String main to store the first word of the sentence
l int main to store the length of the word
first char main to store the first character of the word
last char main to store the last character of the word
output String main to store the output sentence

Question 9:
Write a program in java to accept number of sentence and the sentence & display the number of words and
the words in ascending order of their frequency.
Sample input:
Enter number of sentence: 1
Enter sentences: TO BE OR NOT TO BE
Sample output:
Total number of words: 6
Word Frequency
OR 1
NOT 1
TO 2
BE 2
ALGORITHM FOR main ():
Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the number of sentences from the user.

Step 5: If the number of sentences is less than 1 or greater than 3, printing invalid entry.

Step 6: Accepting the sentences from the user.

Step 7: Converting the sentence to uppercase.

Step 8: Creating string tokenizer object.

Step 9: Counting the number of tokens in the sentence.

Step 10: Printing the total number of tokens.

Step 11.1: Running a loop till the word count.

Step 11.2: Extracting each token and checking the equality.

Step 12: Sorting word frequency in ascending order.

Step 13: Printing the words with their frequencies.

Step 14: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
n int main to store the number of sentences
s String main to store the sentence
wordCount int main to count the number of words in the sentence
wordArr String main to store the words in the sentence
wordFreq int main to store the characters in each word
idx int main to store the index value
i int main outer loop variable
j int main inner loop variable
word String main to extract the words from the sentence
t int main to swap the values
temp String main to swap the values

Question 10:
Write a program in java to accept a sentence & display the number of times each word occurs in the entire
text.

Sample input:
Enter sentences: TO BE OR NOT TO BE
Sample output:
Wor Frequency
d
TO 2
BE 2
OR 1
NOT 1

ALGORITHM FOR main():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Converting the sentence to uppercase.

Step 6: Creating string tokenizer object.

Step 7: Counting the number of words in the sentence.

Step 8: Creating an array to store the words of the sentence.

Step 9.1: Running a loop from 0 to the number of words and checking where there are any similar words or
not.

Step 9.2: If true display the word with its frequency.

Step 10: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
s String main to accept the sentence from the user
wordArr String main to store the words in the sentence
wordCount int main to count the number of words in the sentence
wordFreq int main to store the characters in each word
idx int main to store the index value
i int main outer loop variable
j int main inner loop variable

Question 11:
Write a program in java to accept a sentence. Arrange the words contained in the sentence according to the
length of the words in ascending order.

Sample input:
Enter a sentence: Computer science by Sumita arora
Sample output:
Length of the
Words
words
By 2
Arora 5
Sumita 6
Science 7
Computer 8
ALGORITHM FOR main ():

Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Splitting the sentence into words with respect to space.

Step 6: Finding the length of the number of words.

Step 7.1: Running a loop from 0 to the number of words.

Step 7.2: Storing the length of each word.

Step 8: Running a loop to swap the values and arrange the words with their lengths.

Step 9 : End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
sentence String main to accept the sentence from the user
words String main to split the sentence into words with respect to space
w String main to swap values
length int main to store length of number of words
i int main outer loop variable
j int main inner loop variable
len int main to store the length of each word
noofwords int main to store the length of words

Question 12:
Write a program in java to accept sentence and display only the unique words in the sentences and count
them.

Sample input:
Enter a sentence: Computer science by Sumita arora
Sample output:
Unique words in the sentence are: Computer
by
Sumita

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Splitting the sentence into words with respect to space.

Step 6: Printing the output message.

Step 7.1: Running a loop 0 to the length of the word.

Step 7.2: Extracting each characters from the word.

Step 7.3: If the unique is true, print the words.

Step 8: End.
SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
sentence String main to accept the sentence from the user
words String main to split the sentence into words with respect to space
i int main loop variable
unique Boolean main to store the Boolean value as true
word String main to store each word
j int main loop variable
ch char main to extract the characters from the word
pos int main to store the position of the character
Question 13:
Write a program in java to accept a sentence and arrange the sentence in ascending order according the
potential of each word.
A=1
B=2
C=3
.
.
.
Z = 26
The potential of a word is found by adding the encrypted value of the alphabets.

Example 1
KITE
Potential = 11 + 9 + 20 + 5 = 45
Example 2
INPUT: LOOK BEFORE YOU LEAP
POTENTIAL: LOOK – 53
BEFORE – 51
YOU – 61
LEAP – 34
OUTPUT: LEAP BEFORE LOOK YOU

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Converting the sentence to uppercase.

Step 6: Creating string tokenizer object.

Step 7: Storing the total number of tokens present in the sentence.

Step 8: Checking whether there are more tokens or not.

Step 9: Storing each word.

Step 10: Finding the length of each token.

Step 11.1: Running the loop from 0 to the length of each word.

Step 11.2: Extracting each characters from the word.

Step 11.3: Finding the ASCII values and adding it.


Step 12.1: Running a first loop from 0 to the number of tokens.

Step 12.2: Running a second from 0 to the number of tokens.

Step 13: if the value of i is greater than that of j, swapping the values of it and arranging it in ascending
order.

Step 14.1: Running a loop from 0 to the number of tokens.

Step 15: Printing each word.

Step 16 : End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
w String main to store each token
temp String main to swap values
str String main to accept the sentence from the user
k int main counter variable
i int main outer loop variable
j int main inner loop variable
l int main to store the length of each word
s int main to store the position
a int main to store the characters
t int main to swap values
count int main to count the number of tokens present in the sentence
word String main to store each word
pot int main to store the potential of each word

Question 14:
Write a program in java to accept a name and display its numerology number.
(Note: raj= 18 +1 +10 = 29 = 11. 11 is the numerology number of raj. Numerology can be 1, 2, 3, 4, 5, 6,
7, 8, 9 and 11)
Sample input:
Enter your name: Riya
Sample output:
The numerology number of Riya is 8

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the name from the user.

Step5: Converting the name to uppercase.

Step 6.1: Running a loop from 0 to the length of the name.

Step 6.2: Extracting each characters from the name.

Step 6.3: Finding the ASCII value of the character.

Step 6.4: Finding the sum of the ASCII values.

Step 7.1: While the sum is greater than 0, finding the modulus of the sum.

Step 7.2: Finding the sum of the remainders.

Step 7.3: Storing the quotient of the sum.

Step 8: Printing the numerology number.

Step 9: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
sum int main to store the sum of ascii values
d int main to store the sum of remainders
str String main to accept the name from the user
i int main loop variable
ch1 char main to extract characters from the name
ascii int main to store the ascii value of the characters
n int main to find the remainder
str1 String main to convert the name to uppercase

Question 15:
Write a program in java to accept a string. Display the word, which occurs the maximum number of times
within the string.

Sample input:
Enter a sentence: TO BE OR NOT TO BE
Sample output:
The words which occurs the maximum number are
TO BE

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the sentence from the user.

Step 5: Creating String tokenizer object.

Step 6: Counting the number of tokens.

Step 7: Checking whether more tokens are there or not.

Step 8.Running the loop and swapping the values.

Step 9: Printing the values.

Step 10: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
w String main to store each token
word String main to store each token
str String main to accept the sentence from the user
i int main outer loop variable
count int main to count the number of tokens present in the sentence
c int main counter variable
t int main to swap values
j int main inner loop variable

Question 16:
Write a program in java to accept two strings. Display the new string by taking each character of the first
string from the left to right and of the second string from right to left. The letters should be taken
alternatively from each string.

Sample input: 1. HISTORY


2. SCIENCE
Sample output: HEICSNTEOIRCYS

ALGORITHM FOR main ():

Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the first word from the user.

Step 5: Accepting the second word from the user.

Step 6: Finding the length of the first word.

Step 7.1: Running a loop from 0 to the length of the first word.

Step 7.2: Extracting each characters from the beginning of the first word.

Step 7.3: Extracting each characters from the end of the second word.

Step 7.4: Adding both the characters and storing it in a new variable.

Step 8: Printing the new word.

Step 9: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
s1 String main to accept the first word from the user
s2 String main to accept the second word from the user
newStr String main to store the new word
len int main to store the length of the first word
i int main loop variable
ch1 char main to extract the first character of the first word
ch2 char main to extract the last character of the second word

Question 17:
Write a program in java to accept word and print all the probable letters combinations.

Sample input: TOP


Sample output: TOP
TPO
OPT
OTP
PTO
POT

ALGORITHM FOR main ():

Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating scanner object.

Step 4: Accepting the word from the user.

Step 5: Finding the length of each word.

Step 6: Printing the message “the combination of each word”.

Step 7.1: Running a first loop from 0 to the length of the word.

Step 7.2: Running a second loop from 0 to the length of the word.

Step 7.3: Running a second loop from 0 to the length of the word.

Step 7.6: Checking if i is not equal to j , j is not equal to k and k is not equal to i.

Step 7.7: If true, adding the characters of the three loops and printing it.

Step 8: End.

SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOP DESCRIPTION
NAME TYPES E
s String main to accept the word from the user
len int main to store the length of the word
i int main outer loop variable
j int main inner loop variable
k int main inner most loop variable
Question 18:
Assume that there can be maximum 10 sentences in a paragraph. Write a program to arrange the sentences
in increasing order of their number of words.

Example
INPUT: Please come and attend the party. Hello! How are you?
OUTPUT: 
Hello = 1
How are you = 3
Please come and attend the party = 6

ALGORITHM FOR main ():


Step 1: Start.

Step 2: Declaring the class name.

Step 3: Creating object with the class name.

Step 4: Creating scanner object.

Step 5: Accepting the paragraph from the user.

Step 6: Creating string tokenizer object.

Step 7: Counting the number of sentences in the paragraph.

Step 8.1: If the number of sentences is greater than 10, printing a message that a minimum of 10 sentences
are allowed in the paragraph.

Step 8.2: Otherwise storing each sentence in an array and then running a loop from 0 to the number of
sentences and counting the number of words and printing it.

Step 9: End.

ALGORITHM FOR countWords ():

Step 1: Start.

Step 2: Accepting string from the console.

Step 3: Creating string tokenizer object.

Step 4: Counting the number of tokens and returning the value.

Step 5: End.
ALGORITHM FOR sort ():
Step 1: Start.

Step 2: Finding the length of each word.

Step 3.1: Running a loop from 0 to the length of each word.

Step 3.2: Swapping the values by using a third variable and arranging it in descending order.

Step 4: Printing the result.

Step 5: End.

ALGORITHM FOR printResult ():


Step 1: Start.

Step 2: Finding the length of each word.

Step 3.1: Running a loop from 0 to the length of the word.

Step 3.2: Printing the words.

Step 6: End.
SOURCE CODE:
OUTPUT:
VARIABLE DESCRIPTION:
VARIABLE DATA SCOPE DESCRIPTION
NAME TYPES
c int function to count the number of tokens
n int function to store the length of the word
t1 int function to swap the integer values
t2 String function to swap the words
i int main outer loop variable
j int main inner loop variable
pg String main to accept the paragraph from the user
count int main to count the number of sentences
sent String main to store each sentence
p int function to store the words
w String function to store the words
s String function to accepting the sentence

METHOD DESCRIPTION:
METHOD RETURN ARGUMENT LIST PURPOSE
NAME TYPE
count int String s to return the number of tokens
sort void String w[ ] , int p[ ] to sort the sentences in ascending order
printResult void String w[ ] , int p[ ] to print the arranged sentences

You might also like