2016-07-26 29 views
-1

我必須決定我的輸入是增加還是減少。 例如,如果它是1234,它會說Increasing!8765Decreasing! 我需要添加淺增加和減少。我如何才能將寬鬆增加的數字用作我的一個條件?

像這樣:

  • 344343 =>Shallow increase!
  • 443343 =>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! 
+0

12321呢? – shmosel

+0

因此,這也將被視爲/或者,對嗎? 44444,12321或12121將會處於相同的狀態..你認爲我是對的嗎? – user27691

+0

我不知道。你的要求來自哪裏? – shmosel

回答

0

你可以嘗試把(第一< =第二& &第二< = ||第三第三個爲< =第一個)用於淺度增加,並且對於淺度減小,放置(第一> =第二個& &秒> =第三個||第三個> =第一個)。此外,測試他們是否都是平等的,並把/或。

+0

你在做每個人的Java書嗎,BC我正在做同樣的事情:) – user6697247

相關問題