jeudi 28 août 2014

Java Print out Most freq appearing letter in a string


Vote count:

0




I am new to java and i need help in print out most frequent appear letter in a string that the user enter.Below is the code that i think of and it does not work what i expected to do.Could anyone see the code below and tell me what i did wrong. Thanks!



package testing;
import java.util.Scanner;

public class test {

public static void main(String[] args){
String smalltext ,bigtext;
int freq =0;
int appear =0;
int maxappear =0;
Scanner sc = new Scanner(System.in);
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();

System.out.print("Enter String :");
smalltext= sc.nextLine();
bigtext=smalltext.toLowerCase();

for(int i=0;i<alphabet.length;i++) {

for(int j=0;j<bigtext.length();j++){
if(alphabet[i]==bigtext.charAt(j)){
appear++;
if(maxappear<appear){
freq = i;

}
}

}

}
System.out.print("Most Appear Letter is "+alphabet[freq]);


asked 18 secs ago







Java Print out Most freq appearing letter in a string

Aucun commentaire:

Enregistrer un commentaire