the current code I have lists the frequency of an array of letters and I was wondering if there was a way to incorporate numbers and all punctuation available to the user. (i.e. ASCII text) I appreciate any help!
import java.util.Scanner;
public class JavaProgram
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
int i = 0;
int j = 0;
int k = 0;
String str;
char c, ch;
System.out.print("Enter a String : ");
str=scan.nextLine();
i=str.length();
for(c='A'; c<='z'; c++)
{
k=0;
for(j=0; j<i; j++)
{
ch = str.charAt(j);
if(ch == c)
{
k++;
}
}
if(k>0)
{
System.out.println( c + " " + k );
}
}
}
}
input
Enter a String : jhdvaevaecvieabvuae[;;;/'[298734327
output
[ 2
a 4
b 1
c 1
d 1
e 4
h 1
i 1
j 1
u 1
v 4
Also, this code all ready accommodates for upper and lower case differentiation.