2. Write a program in Java to input three numbers and display the
greatest and the smallest of the two numbers
Hin: Use Math.min() abd Math max()
Sample Input 89, 67,36
Sample Output: Greates Number 89
Smallest number 36
Answers
Answered by
20
Java program:
class Great
{
void main(int a,Int b,int c)
{
int larg=Math.max(a,Math.max(b,c));
int small=Math.min(a,Math.min(b,c));
System.out.println("Greatest number ="+larg);
System.out.println("Smallest number ="+small);
}
}
Output:-
Sample Input: 7,58,99
Greatest number = 99
Smallest number = 7
Explanation:
- Math.max() function is used to find the largest value among two numbers.
- Math.min() function is used to find the smallest value among 2 numbers.
Similar questions