Monday 5 January 2015

Java Program to test Conditional Operator


This is a Java program which implements the conditional operators usage.
Generally a conditional operator is one which has one condition and 2 results for condition true and condition false.

PROGRAM :
package codingcorner.in;

import java.util.Scanner;

public class ConditionalOperators {
public static void main(String[] args) {
int num1, num2, e;
Scanner scan = new Scanner(System.in);
System.out.println("Enter any number:\t");
num1 = scan.nextInt();
System.out.println("Enter another number :\t");
num2 = scan.nextInt();
scan.close();
e = (num1 > num2) ? num1 : num2;
System.out.println(e + " is the greatest of two");
}
}


OUTPUT :

No comments:

Post a Comment