I have some code that counts the number of 4's in a line (from a text file) and prints the results. I did it using the String class but have to switch it to using the Character class and I don't have a clue how to do it. I am just learning Java and this is one of the exercises. Thanks for any and all help. lhuffst
Here is the code that works as a string
Here is the code that works as a string
Code:
String lineInfo = input.nextLine();
// get the number of characters in each line
counts+= lineInfo.length();
[b]
// get the number of 4's in each line
char[] chars = lineInfo.toCharArray();
for (int i = 0; i < chars.length; i++)
{
if (chars[i] == '4')
countFours++;
}
[/b]