如何停止我的代码多次打印“升序”?

问题描述 投票:0回答:1

我的代码是:

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 仅当输入混合或升序时,如何使代码打印?

java arrays string for-loop if-statement
1个回答
0
投票

在我之前回答的人(Elliott Frisch)是PRO我不知道这行是做什么的,以及那些:::

Arrays.stream(input.split("\\s+")).mapToInt(Integer::parseInt).toArray();
© www.soinside.com 2019 - 2024. All rights reserved.