Programs:
public class Count {
public static void main(String arg[]){
String main = "hello welcome to java";
char[] arr = main.toCharArray();
String str[] = main.split(" ");
int wcount[] = new int[str.length];
int ccount[] = new int[27];
for(int i=0;i<str.length;i++){
System.out.println(str[i]);
}
String temp = null;
for(int i=0;i<str.length;i++){
for(int j=0;j<str.length;j++){
if(str[i].compareTo(str[j]) == 0){
wcount[i]++;
}
if(str[i].compareTo(str[j]) < 0){
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
// Sorted words and word count
System.out.println("Word count: " + str.length);
for(int i=0;i<str.length;i++){
System.out.println(str[i] + " " + wcount[i]);
}
}
}
public class Count {
public static void main(String arg[]){
String main = "hello welcome to java";
char[] arr = main.toCharArray();
String str[] = main.split(" ");
int wcount[] = new int[str.length];
int ccount[] = new int[27];
for(int i=0;i<str.length;i++){
System.out.println(str[i]);
}
String temp = null;
for(int i=0;i<str.length;i++){
for(int j=0;j<str.length;j++){
if(str[i].compareTo(str[j]) == 0){
wcount[i]++;
}
if(str[i].compareTo(str[j]) < 0){
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
// Sorted words and word count
System.out.println("Word count: " + str.length);
for(int i=0;i<str.length;i++){
System.out.println(str[i] + " " + wcount[i]);
}
}
}
No comments:
Post a Comment