dimanche 3 mai 2015

Java program exit function not working

i'm a newbie to java so i decided to create a simple program that prints out even numbers. I tried to make it exit a while loop if you answered no to the question but it just keeps on going.

Here's the code

public static void main(String[] args){
    String continueYorN = "Y";
    int i = 0;
    while (continueYorN.equalsIgnoreCase("y")){

        while(i >= 0){
            i++;
            if((i%2) == 0){
                System.out.println(i);
                continue;
        }
            System.out.println("Do you want to generate another even number?");
            continueYorN = userInput.nextLine();
    }

    }

}

Aucun commentaire:

Enregistrer un commentaire