Hi java peoples,
I just recently started programming java, and I having a problem with my program. I'm trying to determine the number of even, odd, and zero digits in a number inputted by the user. It counts even and odd digits fine, however, it determines every zero digit to be an even digit. For example, when I enter a number like 140, the program says that there are 2 evens, 1 odd, and 0 zeros, where it should be 1 even, 1 odd, and one zero. Any help would be appreciated.
public class Project_6 { public static void main (String[] args) { System.out.print ("Enter a number: "); String value = Keyboard.readString(); int evens = 0; int odds = 0; int zeros = 0; int count = 0; int value_int; while (count < value.length()) { value_int = value.charAt(count); if (value_int % 2 != 0) odds++; else { if (value_int == 0) zeros++; else evens++; } count++; } System.out.println ("\nEven digits: " + evens + "\nOdd digits: " + odds + "\nZero digits: " + zeros); } }