-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