Wednesday, 2 October 2013

Creating a loop and switch statement

Creating a loop and switch statement

I need to use a switch statement and the loop of my choice to create a
program that looks like this when I run it :
System.out.println("Enter an integer to check if it's odd or even. Or,
enter 7 to quit.");
At this point, if the user enters in 7, the loop ends and the question is
not asked again. IF anything but 7 is entered, then the following logic
needs to be coded:
a) evaluate whether the user entered in an even or odd number, and store
the result as 0 or 1 respectively. This result will be evaluated by your
switch structure. Depending on the result, output "The number is odd", or
"The number is even".
b) loop back to the beginning and start the process again, including
asking the user to enter another number in.
Now I know how to figure out if it is even or odd... I will use modulus. I
am just confused as to how I need to construct the loop. Sorry, I know
this may seem so simple, but I am brand spankin new at this and it is
difficult for me to see what loop would be best. Thanks!

No comments:

Post a Comment