Wednesday, January 21, 2015

Java program to check the number whether it is odd or even


The java program given below will check a number whether it is odd or even. After running the program, you will be asked to provide a number. Later that number will be checked to find out whether it is odd or even. Finally a message will be displayed to inform you if the number is odd or not.
odd or even number,java program,whether odd or even

import java.util.Scanner;

public class OddEven{
 public static void main(String [] args){
  //integer type variables declaration
  int number, remainder;

  //getting input a number from keyboard
  Scanner in = new Scanner(System.in);
  System.out.print("Enter the number you want to check: ");
  number = in.nextInt();

  //checking for remainder
  remainder = number%2;

  //if else statement to make a decision
  if(remainder==1){
   System.out.println("The number is Odd");
  } else {
   System.out.println("The number is Even");
  }
 }
}


No comments:

Post a Comment