编写一个java Application 程序,接受用户输入的5个整数,并输出这5个整数的最大和最小值
展开全部
static void run() {
Scanner scanner = new Scanner(System.in);
int[] is = new int[5];
for (int i = 0; i < is.length; i++) {
System.out.print("请输入第" + (i + 1) + "个整数:");
String str = scanner.next();
if (str.matches("[0-9]+")) {
is[i] = Integer.parseInt(str);
} else {
i--;
System.out.println("\n限制只能输入整数!");
}
}
System.out.println("您输入的是:" + Arrays.toString(is));
Arrays.sort(is);
int max = is[is.length - 1];
int min = is[0];
System.out.println("您输入的最大数是:" + max);
System.out.println("您输入的最小数是:" + min);
}
Scanner scanner = new Scanner(System.in);
int[] is = new int[5];
for (int i = 0; i < is.length; i++) {
System.out.print("请输入第" + (i + 1) + "个整数:");
String str = scanner.next();
if (str.matches("[0-9]+")) {
is[i] = Integer.parseInt(str);
} else {
i--;
System.out.println("\n限制只能输入整数!");
}
}
System.out.println("您输入的是:" + Arrays.toString(is));
Arrays.sort(is);
int max = is[is.length - 1];
int min = is[0];
System.out.println("您输入的最大数是:" + max);
System.out.println("您输入的最小数是:" + min);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询