i was hoping someone could tell me how i can make my code as it is accept a string that has to be inputted into the code before running it. So basically my code right now asks for words(string) to be written by the user when its running i need to go back to just having string = "" i think something like that i edited this a lot. i hope i've not been silly with my description of what i need any help would be appreciated thank you.
import java.io.*;
public class testjavafile04
{
public static void main(String args[]) throws IOException
{while(true)
{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Words: ");
String s = br.readLine();
int l=s.length();
s=s.toLowerCase();
char ch;
System.out.println("Letter\tCount");
int count=0;
int[] charcount= new int[26];
for(int i=0; i<26; i++)charcount[i] = 0;
for(char i='a'; i<='z'; i++)
{
for(int j=0; j<l; j++)
{
ch=s.charAt(j);
if(ch==i)
{
count++;
charcount[i-97]++;
}
}
}
for(char i='a'; i<='z'; i++)
{
System.out.println(i+"\t"+ (float)charcount[i-97]*100/count);
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire