我的节目没有结束

时间:2014-03-14 03:12:55

标签: java while-loop infinite-loop

我的节目没有结束。我是初学者,我很难理解为什么。在我更改名称之前它工作正常,所以我将其复制到另一个文件,但它仍然没有结束。

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]); 
                }
            }

         } 
    }
}

我很感激任何建议。

1 个答案:

答案 0 :(得分:3)

问题在于:

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

这是一个无限循环,因为你永远不会改变其中i的值。只需对其进行评论即可完成申请。然后,花一些时间考虑如何修复它或者你想用这个循环完成什么。