Google Search

Monday, March 2, 2015

write a Java program to check whether the no is even or odd



ALGORITHM:

Step 1: Start

Step 2: Read the no n

Step 3: If n%2 = 0 then print even

Step 4: If n%2=1 then print odd

Step 5: Stop

PROGRAM: import java.io.*; class clsevenodd

{public static void main(String args[])throws IOException

{BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int n;
System.out.println("Enter the no:"); n=Integer.parseInt(br.readLine()); if(n%2==0)

{

System.out.println("EVEN");}

if(n%2==1)

{System.out.println("ODD");}

}

}

OUTPUT:

D:\JAVA>javac clsevenodd.java D:\JAVA>java clsevenodd Enter the no:

10 EVEN
D:\JAVA>java clsevenodd Enter the no:
9 ODD
D:\JAVA>


0 comments:

Post a Comment