如何修复错误"语法错误,插入"}"完成声明"?

时间:2015-09-27 14:19:23

标签: java drjava

找到1个错误:

  

文件:C:\ Users \ little \ OneDrive \ lab_2.java [line: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;
             }
     }

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

1 个答案:

答案 0 :(得分:1)

您在}方法的末尾缺少main

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

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

相关问题