0

1または2または3を選択し、プログラムを実行してオプションメニューを選択した後...1または2を選択した後にプログラムを終了したくない場合はどうすればよいですか...事前に感謝します。

これは私の選択オプションプログラムです...

public class Dialog
{

        AddList ad = new AddList();
        int select;
        void showDialog()
        {
            System.out.println("Enter The 1 for addnig data");
            System.out.println("Enter The 2 for Waching the MARK data");
            System.out.println("Enter The 3 for Waching the NAME data");
            System.out.println("Enter The 4 for Waching All the data of students");
            System.out.println("Enter The 5 for Waching SUM of the mark of Students");
        }

        void progressInput()
        {

            Scanner scan = new Scanner(System.in);
            select = scan.nextInt();

            if (select == 1)
            {
                ad.AddListIntoArray();
            }
            else if (select == 2)
            {
                ad.PrintMarkFromTheArray();
            }
            else if (select == 3)
            {
                ad.PrintNameFromTheArray();
            }
            else if (select == 4)
            {
                ad.PrintNameMarkFromTheArray();
            }
            else if (select == 5)
            {
                ad.SendMark();
            }
            else
            {
       System.out.println("Please Input range from 1 to 5 and not something else");
            }
        }
}

これが私のメインプログラムです....ここではすべて問題ありませんが、1または2を選択した後、プログラムを終了したくありません。つまり、プログラム1を実行して結果を表示し、選択オプションメニューに戻ります...

public class Main
{

    public static void main(String[] args)
    {

         Dialog dlg = new Dialog();
         dlg.showDialog();
         dlg.progressInput();

    }

}
4

2 に答える 2

2

コードをwhile(true)ループ内に配置します。

Dialog dlg = new Dialog();
while(true){
    dlg.showDialog();
    dlg.progressInput();
}
于 2012-12-30T17:10:21.623 に答える
0

追加

System.out.println("Enter The 1 for addnig data");
System.out.println("Enter The 2 for Waching the MARK data");
System.out.println("Enter The 3 for Waching the NAME data");
System.out.println("Enter The 4 for Waching All the data of students");
System.out.println("Enter The 5 for Waching SUM of the mark of Students");
System.out.println("Enter The 6 for Exit");

それから

Scanner scan = new Scanner(System.in);
int select = 0;
do {
    System.out.println("Enter your option");
    select = scan.nextInt();
    if (select == 1) {
        ad.AddListIntoArray();
    } else if (select == 2) {
        ad.PrintMarkFromTheArray();
    } else if (select == 3) {
        ad.PrintNameFromTheArray();
    } else if (select == 4) {
        ad.PrintNameMarkFromTheArray();
    } else if (select == 5) {
        ad.SendMark();
    }else if (select == 6) {
        System.out.println("Exiting...");
    }
    else {
        System.out.println("invalid input");
    }
} while (select != 6);
于 2012-12-30T17:16:10.397 に答える