Page 543 - Cs_withBlue_J_C11_Flipbook
P. 543
The output of the preceding program is as follows:
Enter a string:
India is great
Original String : India is great
New String : aidnI si taerg
Variable Description
NAME TYPE DESCRIPTION
str String Sentence taken from the user
nwstr String Sentence to be formed
len int Length of the sentence
wd String Word extracted from sentence
wdlen int Length of the word
i int Loop variable
Program 22 To find the shortest and longest words in a string assuming that length of each word in the
string is different. If there are two or more words with the same length that happen to be the
shortest or longest words, then this code outputs the one that falls last in the given string.
1 import java.util.*;
2 class largesmall
3 {
4 String str1,large,small;
5 int len;
6 void input()
7 {
8 Scanner sc=new Scanner(System.in);
9 System.out.print("Enter a Sentence : ");
10 str1=sc.nextLine();
11 System.out.println("Given Sentence : "+str1);
12 large="";
13 small="";
14 len=str1.length();
15 }
16
17 void findlargesmall()
18 {
19 String wd;
541
Internal Assessment 541

