Page 252 - Computer science 868 Class 12
P. 252
24 s1="";
25 if(c>0)
26 l-=c;
27 }
28 return s;
29 }
30
31 public static void main()
32 {
33 Scanner sc= new Scanner(System.in);
34 String w1,w2;
35 System.out.println("Enter a word ");
36 w1=sc.next();
37 w1=w1.toLowerCase();
38 w2=remove(w1);
39 System.out.println("Original String: "+w1);
40 System.out.println("String after removing duplicates: "+w2);
41 }
42 }
The output of the preceding program is as follows:
Enter a word
Bharat
Original String: bharat
String after removing duplicates: bhart
Program 5 Write a program to find the shortest and the longest words in a given string using indexOf()
method.
1 class find_short_long
2 {
3 void find_word(String s)
4 {
5 String str=s+" ";
6 int len=str.length(), l=0;
7 int start_index=0, last_index;
250250 Touchpad Computer Science-XII

