write program to find largest number among three number and display the output
Answers
Answered by
5
The given problem is solved using language - Java.
import java.util.Scanner;
public class Java{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int a,b,c,max;
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();
max=Math.max(a,Math.max(b,c));
System.out.println("Largest number is: "+max);
}
}
- Math.max() function returns the highest among two numbers.
- To calculate highest among three numbers, first calculate the highest and any two numbers and then compare the highest value with the third number to get the largest number.
See the attachment for output.
Attachments:
Similar questions