-1
我必須決定我的輸入是增加還是減少。 例如,如果它是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!
12321呢? – shmosel
因此,這也將被視爲/或者,對嗎? 44444,12321或12121將會處於相同的狀態..你認爲我是對的嗎? – user27691
我不知道。你的要求來自哪裏? – shmosel