Output:
Click Here For Java Online Compiler
Solution:
*** Largest Number Using Ternary Operator *** Enter First Number: 5 Enter Second Number: 4 Enter Third Number: 7 Largest Number is: 7
Click Here For Java Online Compiler
Solution:
import java.util.Scanner; public class LargestUsingTernary { public static void main(String[] args) { int num1, num2, num3, result, temp; Scanner scanner = new Scanner(System.in); System.out.println("*** Largest Number Using Ternary Operator ***" + "\n"); System.out.println("Enter First Number:"); num1 = scanner.nextInt(); System.out.println("Enter Second Number:"); num2 = scanner.nextInt(); System.out.println("Enter Third Number:"); num3 = scanner.nextInt(); scanner.close(); temp = num1 > num2 ? num1 : num2; result = num3 > temp ? num3 : temp; System.out.println("Largest Number is: " + result); } }
comment 0 comments:
more_vertsentiment_satisfied Emoticon