Wednesday, 9 October 2013

Program to chech even or odd using cmdline and ternary operator

//Program to chech even or odd using cmdline and ternary operator
//Developed by Ahlam Ansari

import java.io.*;
class EvenOdd
{
    public static void main(String ahlam[])
    {
        int num=Integer.parseInt(ahlam[0]);   
        String s=(num%2==0)?"even":"Odd";
        System.out.println(num+" is " + s);
    }
}

/*
Output

C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>javac EvenOdd.java

C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java EvenOdd 123
123 is Odd

C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>java EvenOdd 122
122 is even

C:\Users\Ahlam\Google Drive\My Lectures\Fall\OOPM\Programs>
*/

No comments:

Post a Comment