My code is:
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");
}
}
But when my input is1 2 3 4 5 6, the output is: Ascending Ascending Ascending Ascending Ascending And when my input is 1 4 2 5 2, the output is, Ascending Mixed Ascending Mixed How do I make the code print only if the input is mixed or ascending?
Aucun commentaire:
Enregistrer un commentaire