[Java] 纯文本查看 复制代码 package com.company.demo;
import java.util.Arrays;
import java.util.Scanner;
public class Demo_test00 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入第三个整数");
int[] arr = new int[3];
for (int i = 0; i < arr.length; i++) {
String string = scanner.nextLine();
if(string.matches("[0-9]+")){
arr[i] = Integer.parseInt(string);
}else{
i--;
System.out.println("非int数据,请重新输入...");
}
}
Arrays.sort(arr);
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
scanner.close();
}
}
|