I'm having a bit of trouble with this do while loop. The system will print out the line and stop. What am I doing wrong? Thank you for your time!
Scanner keyboard = new Scanner(System.in);
String answer;
int inputNum = 1;
int countOdd = 0;
int countEven = 0;
do{
do{
System.out.println("Please enter an interger. When you are finished, enter 0.");
inputNum = keyboard.nextInt();
while (inputNum % 2 == 0)
countOdd++;
while (inputNum % 2 != 0)
countEven++;
}while(inputNum != 0);
System.out.println("Thank you. The amount of odd intergers you entered is "
+ countOdd + ". The amount of even intergers you entered is " + countEven);
System.out.println("Thank you. The amount of odd intergers you entered is "
+ countOdd + ". The amount of even intergers you entered is " + countEven);
System.out.println("Would you like to run this program again? (Y) (N)");
answer = keyboard.nextLine();
}while (answer.equals("Y"));
System.out.println("Thank you!");
}
}
{?"The system will print out the line and stop"So what is it printing and what is your expected output?nextLineisn't the problem. (But it will be your next problem after you fix the while/if problem)