Write a program in Java to find the greatest of three numbers using ternary operator.
Answers
Answered by
5
public class JavaExample
{
public static void main(String[] args)
{
int num1, num2, num3, result, temp;
Scanner scanner = new Scanner(System.in);
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);
}
}
Answered by
3
Answer:
hope it helped you and you like it and plz follow me and marked it as brainlist
Attachments:
Similar questions