Search This Blog

If you have any problem or question please write in the comments. We will try to solve and send you the solution. Not just that we will also post your problems solution on our blog.

Wednesday, 22 June 2011

Use of TERNARY operator in java program

import java.util.*;
class ternary
public static void main (String arg[])
Scanner in = new Scanner (;
int a,b,c;

System.out.print ("\n\t Enter first number = ");

System.out.print ("\n\t Enter second number = ");

a==b ? c=1:c=5;
System.out.println ("\n\t c = "+c);


          After entering values, in the above program, computer will check that whether 'a' is equal to 'b' or not. If 'a' is equal to 'b' than
  • c = 1 will be displayed
Otherwise " c = 5 " will be displayed

No comments:

Post a Comment