Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Write a program to determine if number is even or odd

  1. /*
  2.  * Write a program to determine if number is even or odd. Program should take
  3.  * the number from command line argument.
  4.  *
  5.  */
  6.  
  7. import java.io.*;
  8.  
  9. public class OddEvenNumbers
  10. {
  11.  public static void main(String[] s)
  12.  {
  13.   int n=0;
  14.   DataInputStream d1 = new DataInputStream(System.in);
  15.  
  16.   try{
  17.    
  18.    System.out.print("Enter A number: ");
  19.    n = Integer.parseInt(d1.readLine());
  20.  
  21.   }catch(Exception e){
  22.    
  23.    System.out.println("Error Occured during IO");
  24.   }
  25.  
  26.   if(n%2 == 0)
  27.    System.out.println(n + " is Even Number");
  28.   else
  29.    System.out.println(n + " is Odd Number");
  30.  
  31.  }
  32. }
Your rating: None Average: 3 (2 votes)
Share this

Post new comment