Showing posts with label conditional operator. Show all posts
Showing posts with label conditional operator. Show all posts

Sunday, November 2, 2014

, , , ,

Program to print given number is even or odd numbers using conditional operator in command line argument .



Code Box
------------------------------------------

/* Program to print given number is even or odd numbers using 
conditional operator in command line argument */


class evenc
{
public static void main(String x[])
{
int a;
String s;

a=Integer.parseInt(x[0]);

s=(a%2==0)?"a is even":"a is odd";

System.out.print("\n"+s);

}

}
Publisher: Brijmohan Lal Sahu - 3:41 AM
, , ,

Program to print greater number in 3 numbers using conditional operator in command line argument.



Code Box
-------------------------------------

/* Program to print greater number in 3 numbers using 
conditional operator in command line argument */


class greaterc3
{
public static void main(String x[])
{
int a,b,c;

String s;

a=Integer.parseInt(x[0]);
b=Integer.parseInt(x[1]);
c=Integer.parseInt(x[2]);

s=(a>b && b>c)?"a is greater a="+a:((b>c)?"b is grater b="+b:"c is grater c="+c);

System.out.print("\n"+s);

}

}
Publisher: Brijmohan Lal Sahu - 3:29 AM
, , , ,

Program to print greater number in 2 numbers using conditional operator in command line argument.



Code Box
-----------------------------------------

/* Program to print greater number in 2 numbers using 
conditional operator in command line argument */


class greaterc
{
public static void main(String x[])
{
int a,b;

String s;

a=Integer.parseInt(x[0]);
b=Integer.parseInt(x[1]);


s=(a>b)?"a is greater a="+a:"b is grater b="+b;

System.out.print("\n"+s);

}

}
Publisher: Brijmohan Lal Sahu - 3:26 AM