hi its mery , and iam new i have this code
i have this code :
public class NewClass {
public static void main(String[] args) {
String s = JOptionPane.showInputDialog("Enter a string:");
int[] counts = countLetters(s.toLowerCase());
String output = "";
for (int i = 0; i < counts.length; i++) {
if (counts[i] != 0)
output += (char)('a' + i) + " appears " +
counts[i] + ((counts[i] == 1) ? " time\n" : " times\n");
}
JOptionPane.showMessageDialog(null, output);
}
public static int[] countLetters(Sring s) {
int[] counts = new int[26];
for (int i = 0; i < s.length() ; i++) {
if (Character.isLetter(s.charAt(i)))
counts[s.charAt(i) - 'a']++;
}
return counts;
but i need to appears letter A times only , not all litters, plz help me
Re: hi its mery , and iam new i have this code
Change the code inside the loop in the count method to test each character in the String against the desired letter and to increment the count when the desired letter is found.