Write a program to input three numbers and check whether they are equal or not. If they are unequal numbers then display the greatest among them otherwise, display the message 'All the numbers are equal'.
Sample Input: 34, 87, 61
Sample Output: Greatest number: 87
Sample Input: 81, 81, 81
Sample Output: All the numbers are equal.
Answers
Answer:
import java.util.*;
class prog
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter three numbers ");
int n1=sc.nextInt();
int n2=sc.nextInt();
int n3=sc.nextInt();
int c;
if(n1==n2&&n2==n3&&n1==n3)
{
System.out.println("All three are equal");
}
else
{
c=n1>n2?(n1>n3?n1:n3):(n2>n3?n2:n3);
System.out.println("The greatest number is "+c);
}
}
}
Output 1:
Enter three numbers
34
34
34
All three are equal
Output 2:
Enter three numbers
56
83
12
The greatest number is 83
Explanation:
Using if else statements and conditional operator.
Please do mark this as Brainliest!