-2

发现 1 个错误:

文件:C:\Users\little\OneDrive\lab_2.java [行:70] 错误:语法错误,插入“}”完成语句

我是 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;
             }
     }

我需要帮助找出这段代码有什么问题。我做了它,所以它可能不太容易阅读,因为我是初学者。

4

1 回答 1

1

}在方法结束时丢失了main

我可以在您的代码中看到许多其他问题,其中许多问题被不正确的缩进所掩盖。DRJava 可以自动修复代码中的缩进;例如使用此处IndentFiles描述的实用程序。我强烈建议您使用它...然后查看代码以了解我在说什么。

提示:在 之后IndentFiles,缩进看起来不正确,但它会反映你的代码(如所写的)实际上在说什么。

于 2015-09-27T14:39:58.630 回答