Java Code/Program - Check/Test Number Even/Odd
by matt392 in Circuits > Software
224 Views, 2 Favorites, 0 Comments
Java Code/Program - Check/Test Number Even/Odd

Short Java program that asks the user to type in a number, uses the Modulus operator to find a remainder to test to see if it is even or odd.
Attached.
Downloads
Jave Code Below and Attached
import java.util.Scanner;
class MattROddEvenTest
{
public static void main(String args[]) {
Scanner keyboardInput = new Scanner(System.in);
int numberEntered;
int modulusResult;
System.out.println("Please enter an integer number to determine if it is even or odd: ");
numberEntered = keyboardInput.nextInt();
// Divide by 2 using modulus
modulusResult = numberEntered % 2;
System.out.print("The modulus result is: ");
System.out.println(modulusResult);
// Now test to see if the remainder is "Zero"
// If it is zero, then it is an even number
if (modulusResult == 0) {
System.out.println("The number entered was even.");
} // end if loop
else {
System.out.println("The number entered was odd.");
} // end else loop
} // end public static void main
} // end class MattREvenOddTest