Java 如何对程序进行编码以返回到if-else语句之前的代码

Java 如何对程序进行编码以返回到if-else语句之前的代码,java,if-statement,Java,If Statement,如果在我的程序结束时,我想询问用户是否希望使用If-else语句再次执行操作 System.out.println("What Is The Length Of Side A In cm?"); sideA=read.nextDouble(); } System.out.println("What Is The Length Of Side B In cm?"); sideB=read.nextDouble(); } System.out.println("The Triangle Hy

如果在我的程序结束时,我想询问用户是否希望使用If-else语句再次执行操作

System.out.println("What Is The Length Of Side A In cm?");
sideA=read.nextDouble();

}

System.out.println("What Is The Length Of Side B In cm?");
sideB=read.nextDouble();

}

System.out.println("The Triangle Hypotenuse ="+Hypotenuse(sideA,sideB)+"cm");

System.out.println("Do you want to preform this operation again, answer  with yes or no "); 
answer=input.next();
if (answer.equals("no") || answer.equals("No"))
  repeat=false; 
} else
  continue; 
}
现在,如果我试图编译代码,我会在“continue”语句中得到一个错误
我不知道如何使程序再次执行该操作。

您最好使用
循环来执行此操作

boolean repeat = true;
while (repeat) {
    System.out.println("What Is The Length Of Side A In cm?");
    sideA = read.nextDouble();
    System.out.println("What Is The Length Of Side B In cm?");
    sideB = read.nextDouble();
    System.out.println("The Triangle Hypotenuse = " + Math.hypot(sideA, sideB) + " cm");
    System.out.println("Do you want to preform this operation again, answer with yes or no"); 
    answer=input.next();
    if (answer.equalsIgnoreCase("no"))
       repeat = false; 
}
int choice = 1;
  while(choice != -1)
  {
      //code
      System.out.println("again?");
      //get choice
      if(user said no)
       choice = -1;
   }

continue
用于循环,而不是
if else
sy您忘记了while循环?!请张贴,至少,你的整个方法。