-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy paths2.java
More file actions
33 lines (30 loc) · 818 Bytes
/
s2.java
File metadata and controls
33 lines (30 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*Write a program to accept a sentence and sort the letters
* of each word alphabetically and print the modified
* statement
*/
import java.util.*;
import java.io.*;
class s2
{
public static void main()
{
Scanner in=new Scanner(System.in);
String sent=in.nextLine();
StringTokenizer st=new StringTokenizer(sent);
int c=st.countTokens();
System.out.println("No. of words : "+c);
String str="";
while(st.hasMoreTokens())
{
String wrd=st.nextToken().toUpperCase();
for(char ch='A';ch<='Z';ch++)
{for(int i=0;i<wrd.length();i++)
{if(wrd.charAt(i)==ch)
str=str+ch;
}
}
str=str+" ";
}
System.out.println(str);
}
}