write a program in Java to input 3 numbers and find the largest and smallest number using math.max and math. min function
Answers
Answer:
import java.util.Scanner;
public class LargestSmallest {
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter first number: ");
int n1 = in.nextInt();
System.out.println("Enter second number: ");
int n2 = in.nextInt();
System.out.println("Enter third number: ");
int n3 = in.nextInt();
in.close();
int largest = Math.max(n1, Math.max(n2, n3));
System.out.printf("Largest : %d", largest);
System.out.printf("\n");
int smallest = Math.min(n1, Math.min(n2, n3));
System.out.printf("Smallest : %d", smallest);
}
}
Explanation:
Output :
Enter first number:
>>>34
Enter second number:
>>>56
Enter third number:
>>>25
Largest : 56
Smallest : 25
Answer:
above answer is correct
mark me as a Brainlist