Write a program in Java to accept any three numbers and find the
greatest of these numbers.
Answers
Answered by
0
Answer:
This is the required Java program for the question.
import java.util.*;
public class Max {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int a,b,c;
System.out.print("Enter first number: ");
a=sc.nextInt();
System.out.print("Enter second number: ");
b=sc.nextInt();
System.out.print("Enter third number: ");
c=sc.nextInt();
sc.close();
System.out.println("The largest number is: "+Math.max(a,Math.max(b,c)));
}
}
Logic:
- Enter three numbers, say a,b and c.
- Find the maximum of b and c using Math.max() function.
- After finding out the maximum value of b and c, compare that value with a and find the maximum again using Math.max() function.
- Display the greatest value.
Refer to the attachment.
•••♪
Attachments:
Similar questions