Computer Science, asked by Anonymous, 6 months ago

Write a program in Java to input three numbers and display the greatest and the smallest of the two numbers.

Hint: Use Math.min() and Math.max()
Sample Input: 87, 65, 34
Sample Output: Greatest Number 87
Smallest number 34

Answers

Answered by DüllStâr
135

Requested program

important java .until.*;

public class MaxMin

{

public static void main (String [] args)

{

Scanner.sc=new Scanner (System.in);

int a,b,c;

System.out.println("Enter first side:");

a=in.nextInt();

System.out.println("Enter second side:");

b=in.nextInt();

System.out.println("Enter third side:");

c=in.nextInt();

int MAX=Math.max a,(Math.max(b,c));

int MIN=Math.min a,(Math.min(b,c));

System.out.println("Greatest number:"+MAX);

System.out.println("Smallest number:"+MIN);

}

}

Sample input❆

87, 65, 34

Sample output

Greatest number:87

Smallest number:34

Detales about program

  • As told Math.min() and Math.max() function is used✓
  • program is written using scanner class
  • As told program is written using java language✓

Additional information

1)What is max function?

This function is used to find greatest number between two numbers.

2)What is min function?

This function is used to find smallest number between two numbers.

\</strong><strong>s</strong><strong>m</strong><strong>a</strong><strong>l</strong><strong>l</strong><strong>{\</strong><strong>g</strong><strong>r</strong><strong>e</strong><strong>e</strong><strong>n</strong><strong>{\sf \underline{</strong><strong>With\</strong><strong>:</strong><strong> </strong><strong>regards</strong><strong>!</strong><strong>}}}

\small{\</strong><strong>p</strong><strong>i</strong><strong>n</strong><strong>k</strong><strong>{\sf \underline{</strong><strong>★</strong><strong>D</strong><strong>u</strong><strong>l</strong><strong>l</strong><strong> </strong><strong>Star★</strong><strong>}}}

Answered by anindyaadhikari13
12

Question:-

Write a program in Java to input 3 numbers and display the greatest and the smallest of the three numbers.

Program:-

We can use Math.max() and Math.min() function for solving this program easily.

So, here is your program.

class MaxMin

{

public static void main(int a, int b, int c)

{

System.out.println("Largest Number is: "+Math.max(a, Math.max(b, c)));

System.out.println("Smallest Number is: "+Math.min(a, Math.min(b, c)));

}

}

Output:-

Sample Input: 88,55,77

Largest Number is: 88

Smallest Number is: 55

Note:-

  1. Math.max() function is used to find the largest value among two numbers.
  2. Math.min() function is used to find the smallest value among 2 numbers.
Similar questions