188k views
0 votes
1. Create a Java program that asks the user for three

numbers using the Scanner class, and outputs the
smallest number.

User Rtrujillor
by
8.0k points

1 Answer

2 votes

Answer:

Step-by-step explanation:

import java.util.Scanner;

public class SmallestNumber {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the first number: ");

int num1 = scanner.nextInt();

System.out.print("Enter the second number: ");

int num2 = scanner.nextInt();

System.out.print("Enter the third number: ");

int num3 = scanner.nextInt();

int smallest = num1;

if (num2 < smallest) {

smallest = num2;

}

if (num3 < smallest) {

smallest = num3;

}

System.out.println("The smallest number is: " + smallest);

}

}



User Andrei Karcheuski
by
7.4k points