Advertisement
jenniferleigh52

Odd/Even number While loop/Burgess

Jun 30th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. //Odd/Even number While loop
  2. //Jennifer Burgess
  3. //7/28/15
  4. //Exam 1
  5. //This program will prompt user to input a value and then depending on
  6. //what that value is, tell the user if it was even or odd.
  7.  
  8.  
  9. import java.io.*;// Library to use Classes to read data from files and to write data to files
  10. import java.util.Scanner; //Library to use Numeric
  11. class Exam1 // Exam 1
  12. {
  13. public static void main(String[]arg){
  14.      
  15.       int x;
  16.       System.out.println("Enter an integer to check if it is odd or even: ");//Prompt user to
  17.       Scanner in = new Scanner(System.in);                                 //enter number
  18.       x = in.nextInt();//Reads data input
  19.  
  20.       while ( x % 2 == 0 ){//if the number is even, it will output what is written below
  21.          System.out.println("You entered the number " + x + " which is an even number.");
  22.          break;
  23.       }
  24.       while (x % 2 == 1){//if the number is odd, it will output what is written below
  25.          System.out.println("You entered the number " + x + " which is an odd number.");
  26.          break;
  27.        }  
  28.    }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement