2014-03-14 66 views
-1

我的程序沒有結束。我是初學者,無法理解爲什麼。在我更改名稱之前它工作正常,所以我將它複製到另一個文件,但仍然沒有結束。我的程序沒有結束

import java.util.Scanner; 
public class Fan 
{ 
    public static void main (String[] args) 
    { 
     Scanner s = new Scanner(System.in); 
     //first input 
     System.out.println("Enter your first input: "); 
     String first = s.nextLine(); 
     String[] firstsplit = first.split(", "); 
     //second input 
     System.out.println("Enter your second input: "); 
     String second = s.nextLine(); 
     String[] secondsplit = second.split(", "); 
     //third input 
     System.out.println("Enter your third input: "); 
     String third = s.nextLine(); 
     String[] thirdsplit = third.split(", "); 
     //fourth input 
     System.out.println("Enter your fourth input: "); 
     String fourth = s.nextLine(); 
     String[] fourthsplit = fourth.split(", "); 
     //fifth input 
     System.out.println("Enter your fifth input: "); 
     String fifth = s.nextLine(); 
     String[] fifthsplit = fifth.split(", "); 

     for (int a = 0; a<=firstsplit.length-1; a++) 
     { 
     //skipping over values that say how many pieces are on board 
      for (int i = 3; i <= 12; i++) 
      { 
       //compatible with piece numbers up to 12(max) 
       if (Integer.parseInt(firstsplit[0])==i) { 
        while (i >= 1 && i <= Integer.parseInt(firstsplit[i])) { 
        continue; 
        } 
        System.out.println(firstsplit[i]); 
       } 
      } 

     } 
    } 
} 

我將不勝感激任何意見。

+0

您確定'while(i> = 1 && i <= Integer.parseInt(firstsplit [i]))'對於您所有的輸入條件實際上都會計算爲false嗎? – aruisdante

回答

3

的問題是在這裏:

while (i >= 1 && i <= Integer.parseInt(firstsplit[i])) { 
    continue; 
} 

這是一個無限循環,因爲你永遠不會改變的i內它的價值。只是評論它,使您的應用程序完成。然後,花一些時間思考如何解決這個問題,或者你試圖用這個循環來完成什麼。

+0

謝謝。我沒意識到。 – Natrocks