Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获得;表达式“”的开头非法;Java中的错误_Java_Class_Computer Science - Fatal编程技术网

获得;表达式“”的开头非法;Java中的错误

获得;表达式“”的开头非法;Java中的错误,java,class,computer-science,Java,Class,Computer Science,我正在为我的cs12300类编写一些代码。程序说第21行私有字符串RecordSales()是“表达式的非法开始”。这会导致文件无法编译。我怎样才能解决这个问题 import java.util.Scanner; public class Concert { public static void main (String args[]); { int capacity; int soldByPhone; int soldAtVenue; int t

我正在为我的cs12300类编写一些代码。程序说第21行
私有字符串RecordSales()
是“表达式的非法开始”。这会导致文件无法编译。我怎样才能解决这个问题

import java.util.Scanner;

public class Concert
{
  public static void main (String args[]);
  {
    int capacity; 
    int soldByPhone; 
    int soldAtVenue; 
    int totalSalesAmount; 
    int costOfVenue=30; 
    int costOfPhone=35; 

    private String RecordSales() 
    { 
      int totalsales=changePhoneSalestoVenueSales(soldByPhone);
      int total=soldAtVenue+soldByPhone;
      int rtickets=remainingTickets(total);
      return totalsales+" "+rtickets+" "+total; 
    }

    int remainingTickets(int total)
    { 
      return capacity-total;
    }

    int changePhoneSalestoVenueSales(int soldByPhone2) 
    { 
      return soldAtVenue*costOfVenue+soldByPhone2*costOfPhone; 
    }

    public static void main(String args[]) 
    {  
      Concert c=new Concert();  
      Scanner sc=new Scanner(System.in); 
      System.out.println("capacity of the venue:"); 
      c.capacity=sc.nextInt(); 
      System.out.println("Number of ticketsbsold at the venue:"); 
      c.soldAtVenue=sc.nextInt(); 
      System.out.println("Number of tickets sold by phone:"); 
      c.soldByPhone=sc.nextInt(); 
      System.out.println("Total Sales: Remaining tickets: Ticket sold:"); 
      System.out.println("$"+c.RecordSales());
    }
  }

哇。。。这里错得太多了。:-)

我的第一个建议是使用IDE。这将在您学习该语言时为您提供许多关于基本语法的指导


特别是在顶部有一个半写的main方法,它看起来像是剪切粘贴操作的错误。去掉它和它后面的分号;这使编译器无法理解您在与类的其余部分讨论什么。

首先,您有两个主要方法,其中一个以分号结尾。试着去掉这个top-main方法,因为剩下的语法看起来是可以接受的。出现该错误的原因是因为您在方法体中定义了一个方法,这在Java中是不允许的。

您应该从删除第5-6行开始:

public static void main (String args[]);
{

请考虑使用IDE(Eclipse,NETBESE,……),它将帮助您验证语法。非常感谢您帮助我,并做好它。非常感谢!很抱歉,我的无知冒犯了你????我是说,至少我在努力,对吗/你没有冒犯我。这就是笑脸。很高兴您正在学习Java。正如我和其他人所说,如果您找到一个IDE来使用,您将更快地掌握基本语法。它将指导你,并立即(即时)反馈出问题所在。这比在这里问你的问题要快得多