我不知道我这里出了什么问题,但它无法编译。我收到的错误消息是/"else"without "if"//不是语句//"else"without "if"/
我完全按照作业上的示例进行操作,但仍然收到此错误。请有人帮助我使用 Math.PI。我完全迷失了。
import java.util.Scanner;
import java.text.DecimalFormat;
public class CircleCalc
{
public static void main(String[]args)
{
Scanner keyboard = new Scanner(System.in);
double radius;
double area = Math.PI * radius * radius;
double circum = 2 * radius * Math.PI;
DecimalFormat formatter = new DecimalFormat("#0.0000");
int choice;
System.out.println("CIRCLE CALCULATOR MENU");
System.out.println("1) Calculate the Area of a Circle");
System.out.println("2) Calculate the CIrcumference of a Circle");
System.out.println("3) Quit the Program");
System.out.println("Make a selection by choosing a number:");
choice = keyboard.nextInt();
if (choice == 1);
{
radius = 105.7;
System.out.println(" The Area of the Circle with radius 105.7 is " + area);
}
else if (choice == 2);
{
radius = 62.7;
System.out.println("The Circumference of the Circle with radius 62.7 is " + circum);
}
else if (choice == 3);
{
System.out.println("You have chosen to quit the program.");
}
}
}
最佳答案
不要在 if (choice == 1);
之后添加分号,正确的方法是...
if (choice == 1)
{
radius = 105.7;
System.out.println(" The Area of the Circle with radius 105.7 is " + area);
}
else if (choice == 2)
{
radius = 62.7;
System.out.println("The Circumference of the Circle with radius 62.7 is " + circum);
}
else if (choice == 3)
{
System.out.println("You have chosen to quit the program.");
}
关于java - 我在这个程序中做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40207217/