Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Odd/Even number While loop
- //Jennifer Burgess
- //7/28/15
- //Exam 1
- //This program will prompt user to input a value and then depending on
- //what that value is, tell the user if it was even or odd.
- import java.io.*;// Library to use Classes to read data from files and to write data to files
- import java.util.Scanner; //Library to use Numeric
- class Exam1 // Exam 1
- {
- public static void main(String[]arg){
- int x;
- System.out.println("Enter an integer to check if it is odd or even: ");//Prompt user to
- Scanner in = new Scanner(System.in); //enter number
- x = in.nextInt();//Reads data input
- while ( x % 2 == 0 ){//if the number is even, it will output what is written below
- System.out.println("You entered the number " + x + " which is an even number.");
- break;
- }
- while (x % 2 == 1){//if the number is odd, it will output what is written below
- System.out.println("You entered the number " + x + " which is an odd number.");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement