-1
私は4つの異なる方法(下図ではありません)のコードを持っており、ユーザーが選択したい方法を選択するためのメニューを作成しました。whileループを終了するにはどうすればいいですか?
ユーザーが5を入力しない限り、メソッドを常にメニュー画面に戻す方法をループするにはどうすればよいですか?
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class ReactionAnalysis {
public static void main (String [] args) throws FileNotFoundException
{
/// Menu Screen
System.out.println("What would you like to do?");
System.out.println("1: Get the score of a word");
System.out.println("2: Get the average score of words in a file (one word per line)");
System.out.println("3: Find the highest/lowest scoring words in a file");
System.out.println("4: Sort words from a file into positive.txt and negative.txt");
System.out.println("5: Exit the program");
Scanner in = new Scanner(System.in);
System.out.println("Enter a number 1-5");
int numberChoice = in.nextInt();
////
while (numberChoice != 5)
{
if (numberChoice == 1)
{
String methodOne = methodOne();
System.out.println(methodOne);
}
else if (numberChoice == 2)
{
String methodTwo = methodTwo();
System.out.println(methodTwo);
}
else if (numberChoice == 3)
{
String methodThree = methodThree();
System.out.println(methodThree);
}
else if (numberChoice == 4)
{
String methodFour = methodFour();
System.out.println(methodFour);
}
}
}
}
ここまでの手順のうちの1つを実行すると、手順が繰り返されます。ステップを通過してメニューに戻り、メニューに5が入力されていない限り、それを繰り返す必要があります。
あなたのループ内であなたの 'choice'変数**を更新する必要があります。 –
あなたの 'while-loop'でオプションを要求してください。それぞれのメソッドで 'numberChoice = in.nextInt();'を実行して、メソッドを再度選択するようユーザに促します。またはwhileループですべてをラップします。 –
中にコード全体を入れてください。しばらくしてメソッドmainの最初の行に貼り付けてください。 – Paulo