【发布时间】:2016-11-30 18:40:27
【问题描述】:
我必须决定我的输入是按升序还是降序排列。
例如,如果是1234,它会说Increasing! 或者8765 是Decreasing!
我还需要添加浅增加和减少。
像这样:
-
344或343=>Shallow increase! -
443或343=>Shallow decrease! -
444=>either/or!
示例代码:
public class Order {
public static void main(String[] args) {
boolean stop = false;
while(!stop){
Scanner scanner = new Scanner(System.in);
System.out.println("Do you wanna continue? Y or N? ");
char c = scanner.next().charAt(0);
c = Character.toUpperCase(c);
if(c =='Y'){
System.out.println("Please enter a number: ");
Scanner n = new Scanner(System.in);
int s = n.nextInt();
boolean increasing = true;
while ( s> 0) {
int d1 = s % 10;
s/=10;
int d2 = s % 10;
if(d2>d1){
increasing = false;
System.out.println("decreasing!");
break;
}
else{
System.out.println("increasing!");
break;
}
}
}
else {
System.out.println("haha..K ");
stop= true;
}
}
}
}
我想要的输出:
1234 Increasing!
8765 is Decreasing!
344 Shallow increase!
443 Shallow decrease !
444 either/or!
【问题讨论】:
-
因此,这也将被视为非此即彼,对吧? 44444、12321 或 12121 将处于相同的状态。你认为我是对的吗?
-
我不知道。您的需求来自哪里?
-
我很高兴你回来了!
-
我是学生..在我的练习中...
-
你需要真正说出“浅增/减低”是什么意思。
标签: java sorting input numbers digits