Enter any three integer numbers as an input from which you want to find the largest integer. After that we use ternary operator(?, >, : ) to find largest number as the output.
Here is the source code of the Java Program to Find Largest Between Three Numbers Using Ternary Operator. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Largest_Ternary
public static void main(String args)
int a, b, c, d;
Scanner s = new Scanner(System.in);
System.out.println("Enter all three numbers:");
a = s.nextInt();
b = s.nextInt();
c = s.nextInt();
d = c > (a > b ? a : b) ? c : ((a > b) ? a : b);
$ javac Largest_Ternary.java $ java Largest_Ternary Enter all three numbers: 5 6 7 Largest Number:7
Sanfoundry Global Education & Learning Series – 1000 Java Programs.