7-2 sdut-JAVA-the minimum of the numbers
分数 12
全屏浏览
切换布局
作者 马新娟
单位 山东理工大学
Write a program that allows the user to enter four integer numbers. Your program should display the minimum of the numbers entered.
Input Specification:
enter four integer numbers.
Output Specification:
display the minimum of the numbers entered.
Sample Input:
12 35 4 69
Sample Output:
Write the corresponding sample output here. For example:
The minimum number is: 4
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
栈限制
8192 KB
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] b = new int[4]; b[0] = sc.nextInt(); int min = b[0]; for(int i = 1;i<4;i++){ b[i] = sc.nextInt(); if(b[i] <= min){ min = b[i]; } } System.out.println("The minimum number is: " + min); } }