2016-11-20 136 views
-2

所以,如果LARGE不等於Count,然後LARGE應該遞增,直到CountLARGE具有相同的值。事情發生之後,我的教授想再次輸入一個新的整數,然後它會再次循環,但我不知道如何讓我的代碼回到while的Java如何跳回While循環

if (LARGE == Count) 
{ 
    System.out.println ("Large is Equal to Count"); 
} 

while (Count != LARGE) 
{ 
    LARGE++; 
    System.out.println ("Large is " +LARGE); 
} 

if (LARGE == Count) 
{ 
    System.out.println ("Input a new integer to compare") 
    LARGE = input.newInt(); 
} 

回答

0

根據我的理解,這是你想要的。

public static void main(String[] args) { 

     int LARGE = 0; 
     int Count = 0; 
     String s = null; 
     Scanner sc = new Scanner(System.in); 
     do { 

      LARGE = sc.nextInt(); 
      Count = sc.nextInt(); 

      if (LARGE == Count) { 
       System.out.println("Large is Equal to Count"); 
      } else { 
       do { 
        LARGE++; 
        System.out.println("Large is " + LARGE); 
       } while (Count != LARGE); 

       if (LARGE == Count) { 
        System.out.println("Large is Equal to Count"); 
        System.out.println("Input a new integer to compare"); 
       } 

      } 

      System.out.println("Do you want to continue? If yes then Press Y"); 
      s = sc.next(); 
     } while (s.equalsIgnoreCase("Y")); 

    } 
+0

Thankyousomuch我只是第一年學生服用CS但是現在的問題是,當大不等於要計算它將無限循環無論如何在代碼中你寫的其他做的是一樣的,否則如果? –

+0

如果有幫助,請您接受答案。 – PVR

+0

即時新在這裏嗯在哪裏是接受按鈕我很抱歉哈哈 –

0

教授多少次想輸入新的整數,永遠? 我假設它1000次。 如果永遠代替「時間」爲true,而括號別的分配的東西有意義的「次」,而不是1000

System.out.println ("Input a new integer to compare") 
LARGE = input.newInt(); 
int times = 1000; // number of times prof want to enter new integer. 
int loop = 0; 
while(times > loop){ 
    while (Count != LARGE) 
    { 
     LARGE++; 
     System.out.println ("Large is " +LARGE); 
    } 
    System.out.println ("Input a new integer to compare") 
    LARGE = input.newInt(); 
    loop++; 
} 
+0

我不認爲代碼甚至會編譯。 !整數值在while狀態?!!!! – Hiren

+0

謝謝你指出。更正! – vvtx

+0

while(s.equalsIgnoreCase(「Y」))幫助我需要解釋這個答案,我接受的是正確的,但這是代碼我無法解釋謝謝你有人幫助 –