Okay, so my assignment was this: Design and implement an application that determines and prints the number of odd, even, and zero digits in an integer value read from the keyboard.
What should happen is i enter a random number: 1234567890. it would then print out: There are 5 odd numbers. There are 4 even numbers. There are 1 zeroes.
Here is my code i have written so far:
public static void main (String args)
int zero = 0, odd = 0, even = 0, length, left = 0;
System.out.print ("Enter any positive integer: ");
string = Keyboard.readString();
if (string.charAt(left) == 0)
else if (string.charAt(left) % 2 == 0)
System.out.println ("There are: "+ zero + " zeroes.");
System.out.println ("There are: "+ even + " even numbers.");
System.out.println ("There are: "+ odd + " odd numbers.");
The program is compiling just fine, but when i run it i get this error:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException:String index out of range: 9