Number that is a multiple of 9 and all digits are even?

I've writen this short program to find a number that is a multiple of 9 yet all its digits are even. Here is the code. I'm sure its not very compact and am doing this the hard way.
public class alldigitseven
    public static void main(String[] args)
        int number = 0;
        String numberString, tempString;
        char tempChar;
        int tempInt, matches = 0, stringLength;
        double tempRemainder;
        boolean answer = false;
        while (answer != true)
            // add 9 to the number
            if (number < 1000000)
                number += 9;
            // convert the int to a string
            numberString = "" + number;
            stringLength = numberString.length();
            for (int i = 0; i <= stringLength; i++)
                tempChar = numberString.charAt(i);
                tempString = "" + tempChar;
                tempInt = Integer.parseInt(tempString);
                tempRemainder = tempInt%2;
                if (tempRemainder == 0)
                    matches++;
                if (matches == stringLength - 1)
                    System.out.println (numberString);
                    answer = true;
}anways the code complies fine however when I run it, I get the error
"StringIndexOutOfBoundsException:
String index out of range: 1 (in Java.lang.String)"
What do I need to do to fix this?

here was the final code if anyone was curious...
public class alldigitseven
    public static void main(String[] args)
        int number = 0;
        String numberString, tempString;
        char tempChar;
        int tempInt, matches = 0, stringLength;
        int tempRemainder;
        boolean answer = false;
        while (answer != true)
            // reset matches
            matches = 0;
            // add 9 to the number
            if (number < 1000)
                number += 9;
            else
                answer = true;
            // convert the int to a string
            numberString = "" + number;
            stringLength = numberString.length();
            for (int i = 0; i < stringLength; i++)
                tempChar = numberString.charAt(i);
                tempString = "" + tempChar;
                tempInt = Integer.parseInt(tempString);
                tempRemainder = tempInt%2;
                if (tempRemainder == 0)
                    matches++;
                if (matches == stringLength)
                    System.out.println (numberString);
        answer = true;
}

Similar Messages

Maybe you are looking for

  • Km athorization using Trex

    Hello everyone, I am using a anonymous user to access a especific role in my portal. Some of the iviews are km content iviews. They are html archives with navigation to other iviews. To manage to navigate from one iview to other one I use something l

  • RAC Node down and ORA-12514

    I have a two node rac setup. One Node went down because of hardware issues. And it seems that I cannot connect from client (jdbc) when SCAN gives particular ip. I receive : ORA-12514, TNS:listener does not currently know of service requested in conne

  • Installing Oracle 11gR2 client from a batch file and it returns before done

    Hello, While installing Oracle 11gR2 client on XP and 7 from a batch file. When it launches the OUI from the batch file, it returns to the batch file before the installer finishes. So, there is no way for my script to know when the installer is done,

  • Silence the camera shutter sound in an E72

    Hi. I'm using a software called YBrowser to snoop around my Nokia E72 file system. I found out that the sound files for the camera shutter, auto-focus, etc. are located in the following path: z:/system/sounds/digital/relevant-sound-file-name.​wav So

  • I can't find my "setting" folder on my Imac-- how do I get it back?

    I can't find my "setting" folder on my Imac-- how do I get it back? I think it could be deleted