在进入第二个循环后,我的第一个while循环怎么办?

时间:2014-07-28 11:56:35

标签: java

因此,如果我输入的数字不等于28,29,30,31(例如一个月中的几天),我希望我的第一个while循环在第二个循环之后完成。如果你没有得到我可怜的英语尝试运行此代码。我希望这会有所帮助。谢谢。

import java.util.Scanner;

public class Padilla8 {

    public static void main (String args []) {

        int nd, day;

        Scanner in = new Scanner (System.in);

        System.out.print ("Please input number of days: \t");
        nd = in.nextInt ();

        System.out.print ("1 - Monday\n2 - Tuesday\n3 - Wednesday\n4 - "
                + "Thursday\n5 - Friday\n6 - Saturday\n7 - Sunday\n");
        System.out.print ("Enter the corresponding number on what "
                + "day you want the month will start:\t");
        day = in.nextInt ();

        while (nd < 28 || nd > 31) {
            System.out.print ("Months are from 28 days to 31 days only.");
            System.out.print (" Please input number of days:\t");
            nd = in.nextInt ();
        }

        while (day < 1 || day > 7) {
            System.out.print ("Please read.");
            System.out.print ("1 - Monday\n2 - Tuesday\n3 - Wednesday\n4 - "
                    + "Thursday\n5 - Friday\n6 - Saturday\n7 - Sunday\n");
            System.out.print ("Enter the corresponding number on what day "
                    + "you want the month will start:\t");
            day = in.nextInt ();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

请在循环条件下使用标志。 while(日&lt; 1 || day&gt; 7&amp;&amp; flag){ }