-2
1错误:如何解决“语法错误,插入”}“以完成语句”的错误?发现
File: C:\Users\little\OneDrive\lab_2.java [line: 70] Error: Syntax error, insert "}" to complete Statement
我是新来drjava。我的程序有什么问题?
import java.util.Scanner;
class lab_2 {
public static void main (String[]args){
int choice;
Scanner myscan=new Scanner(Systemin);
boolean didntquit=true;
while("didntquit")
//show menu
System.out.println("Please choose an option");
System.out.println("1)Quadratic Function");
System.out.println("2)Distance Formula");
System.out.println("3)Even or Odd");
System.out.println("4)Factorial");
System.out.println("5)Fibonacci");
System.out.println("6)display the digits (in reverse order) of an integer");
System.out.println("7)Quit Program");
//get the option
choice=myscan.nextInt();
//do the option
if (choice=7)
didntquit=false;
//quitint the program ^^^^
else if (choice=1){
int a;
int b;
int c;
System.out.println("what is a ?");
a=myscan.next ;
System.out.println("what is b ?");
b=myscan.next ;
System.out.println("what is c ?");
c=myscan.next ;
double outa =(b + Math.sqrt((b*b)-4*a*c))/(2*a);
double outa =(b - Math.sqrt((b*b)-4*a*c))/(2*a);
}
//quadratic formula ^^^^
else if(choice=2){
System.out.println("What is the x cordinate of the first point?");
int x1 = myscan.nextInt();
int x2 = myscan.nextInt();
int y1 = myscan.nextInt();
int y2 = myscan.nextInt();
double dist = Math.sqrt((x2-x1)*2)+((y2-y1)*2);
}
else if (choice=3){
int x;
System.out.println("Enter an integer to check if it is even or odd");
Scanner in = new Scanner(System.in);
x =in.nextInt();
if (x%2==0)
System.out.println("You entered an even number");
else
System.out.println("You entered an odd number");
}
else if (choice=4){
Scanner scanner = new Scanner(Systemin);
System.out.println("Enter the number");
int num =Scanner.nextInt();
int factorial = fact(num);
System.out.println("factorial of entered number is: "+factorial);
}
static int fact(int n)
{
int output;
if(n==1)
return 1;
output=fact(n-1)*n;
return output;
}
}
我需要帮助弄清楚这段代码有什么问题。我是这样做的,所以它可能不太容易阅读,因为我是初学者。
您的缩进相当杂乱无章,很难看出它是否正确。我希望你的'while()'需要有一个左括号'while(){'开始。也许整理缩进(特别是从'//得到的选项'看起来是不正确的缩进),然后看看大括号丢失的位置? – halfer
几个'if'语句也是错误的:你需要'=='而不是'='来测试是否相等(但它们不是编译错误的原因,@halfer已经给出了这个)。 – WhiteViking
我不知道'while(“didntquit”)'应该是'while(didntquit)' - 如果它是布尔型的,那么引号就不是必须的。你使用核心Java还是特殊版本?我没有听说过drjava。 – halfer