コードを編集して選択メニューをループさせることはできますか?選択肢が5つのオプションのいずれかでない場合、有効なオプションになるまで再入力を促します。可能であれば、説明も参考になります。ありがとうループを使用して選択メニューを検証する方法
ここに私のコードです。
import java.util.*;
public class ShapeLoopValidation
{
public static void main (String [] args)
{
chooseShape();
}
public static void chooseShape()
{
while (true){
Scanner sc = new Scanner(System.in);
System.out.println("Select a shape number to calculate area of that shape!");
System.out.print("Circle = 1. \nRectangle = 2. \nTriangle = 3. \nExit = 4. \nINPUT : ");
int shapeChoice = sc.nextInt();
//while (true) {
if (shapeChoice >= 1 && shapeChoice <=4)
{
if (shapeChoice == 1)
{
circle();
}
else if (shapeChoice == 2)
{
rectangle();
}
else if (shapeChoice == 3)
{
triangle();
}
else if (shapeChoice == 4)
{
return;
}
}
else
{
System.out.print("Error : Choice " + shapeChoice + "Does not exist.");
}
}
class Test {
int a, b;
Test(int a, int b) {
this.a = a;
this.b = b;
}
}
}
正しいコードインデント – mmuzahid
"誰かが自分のコードを編集して選択メニューをループさせることはできますか?選択肢が5つのオプションのいずれかでない場合、有効なオプションになるまで再入力を促します。 "< - あなたのコードはすでにそれを行います。 –