This is a Java Program to Find Largest Between Three Numbers Using Ternary Operator.
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.
import java.util.Scanner;
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);
System.out.println("Largest Number:"+d);
}
}
Output:
$ 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.
advertisement
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Practice Information Technology MCQs
- Practice BCA MCQs
- Check Programming Books
- Apply for Computer Science Internship
- Practice Programming MCQs