295,250 views
41 votes
41 votes
In Java Please!!!!

3.20 LAB: Smallest number Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3

User Andrei RRR
by
3.0k points

1 Answer

10 votes
10 votes

Answer:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int num1 = scanner.nextInt();

int num2 = scanner.nextInt();

int num3 = scanner.nextInt();

int min = Math.min(num1, Math.min(num2, num3));

System.out.println(min);

}

}

Step-by-step explanation:

The program first imports the Scanner class from the java.util package, which allows us to read input from the user. Then, it reads three integers from the user using the nextInt() method of the Scanner class and stores them in variables num1, num2, and num3.

Next, the program calculates the minimum of the three integers using the min() method of the Math class, which takes two integers as arguments and returns the minimum of the two. In this case, we use the min() method twice to find the minimum of all three integers.

Finally, the program prints the minimum value to the console using the println() method of the System.out object.

User ThE USeFuL
by
3.5k points