I am very new to Java and struggling to complete an assignment. I have read several posts but can't seem to figure out how to add the "Enter·y·to·play·again,·n·to·quit(y/n)" into my code. Here is what I have so far. Any direction would be appreciated. I can't figure out how to get it to return to Enter one number. THX
//Program to display Even or Odd Integer
import java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) { //method to determine is a number is even or odd
Scanner input = new Scanner(System.in);
int number; //number o be entered
System.out.print("Enter one number: "); //prompt user to enter a number
number = input.nextInt();
switch (number % 2) {
case 0:
System.out.printf("%d is even\n", number);
case 1:
System.out.printf("%d is odd\n", number);
}
System.out.print("Enter Y to play again, N to quit: "); //prompt user to enter a number
number = input.nextInt();
}
public boolean isEven(int number) {
return number %2 == 0;
} //end method isEven
} //end class EvenOdd
Result:
Enter one number: 1
1 is odd
Enter Y to play again, N to quit: n
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at EvenOdd.main(EvenOdd.java:21)