Write a java program to input any four number from keyboard. Print the largest and the smallest number of the four number
Answers
Answered by
1
Program
import java.util.Scanner;
class Greatest
{
public static void main ( )
{
Scanner sc=new Scanner (System.in);
int a,b,c,d, greatest=0;
System.out.println("Enter the 1st number");
a=sc.nextInt( );
System.out.println("Enter the 2nd number");
b=sc.nextInt( );
System.out.println("Enter the 3rd number");
c=sc.nextInt( );
System.out.println("Enter the 4th number");
d=sc.nextInt( );
greatest=((a>b)&&(a>c)&&(a>d))?a:(((b>c)&&(b>d))?b:(c>d)?c:d);
System.out.println("Greatest number among 4 numbers is "+greatest);
}
}
I m first to answer your question.
Compile the program.
Mark me brainlest.
And follow me for more java related doubts .
Similar questions
Social Sciences,
6 months ago
Science,
6 months ago
Computer Science,
6 months ago
English,
1 year ago
Science,
1 year ago