Page 611 - ComputerScience_Class_11
P. 611
The output of the preceding program is as follows:
BlueJ: Terminal Window - Java
Options
Enter a string:
India is great
Original String : India is great
New String : aidnI si taerg
Program 23 To find the shortest and longest words in a string assuming that the 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;
20 StringTokenizer st=new StringTokenizer(str1);
21 int len1=0,len2=100;
22 while(st.hasMoreTokens())
23 {
Internal Assessment 609

