-
描述
-
设计一个从5个整数中取最小数和最大数的程序
-
输入
- 输入只有一组测试数据,为五个不大于1万的正整数 输出
- 输出两个数,第一个为这五个数中的最小值,第二个为这五个数中的最大值,两个数字以空格格开。 样例输入
-
1 2 3 4 5
样例输出
-
1 5
package nyist.base; import java.util.Scanner; public class Main31 { public static void main(String[] args) { int[] src = getInput(); int min = src[0]; int max = src[0]; for(int j = 1; j < src.length;j++){ //System.out.print(src[j]+" "); if(min > src[j]){ min = src[j]; } if(max < src[j]){ max = src[j]; } } System.out.println(min); System.out.println(max); } public static int[] getInput(){ Scanner scanner = new Scanner(System.in); int [] input = new int[5]; for(int i =0 ; i < 5;i++){ input[i] = scanner.nextInt(); } return input; } }
5个数求最值
最新推荐文章于 2023-02-26 22:34:20 发布