我的代码是:
Scanner sc=new Scanner(System.in);
System.out.println("Type in your order(ex.5 7 4 6 8 3 9 2 0 1 - SPACES REQUIRED): ");
String input=sc.nextLine();
for(int i=0;i<input.length(); i++) {
String[] b=input.split(" ");
if(Integer.valueOf(b[i]) < Integer.valueOf(b[i+1])) {
System.out.println("Acsending");
}
else { // When condition is false
System.out.println("Mixed");
}
}
但是当我的输入为1 2 3 4 5 6
时,输出为:
Ascending
Ascending
Ascending
Ascending
Ascending
当我的输入为1 4 2 5 2
时,输出为
Ascending
Mixed
Ascending
Mixed
仅当输入混合或升序时,如何使代码打印?
在我之前回答的人(Elliott Frisch)是PRO我不知道这行是做什么的,以及那些:::
Arrays.stream(input.split("\\s+")).mapToInt(Integer::parseInt).toArray();