得到错误:';'预期

时间:2013-12-30 10:05:21

标签: java

这是我的代码

import java.util.*;
import java.util.Collections; 

public class Customer
{
 public static void main(String args[]){

 Arraylist listcustomer1 = new Arraylist();
 Arraylist listcustomer2 = new Arraylist();

 Scanner scan = new Scanner(System.in);
 String name,city;
 int custId,numOfPurchases;

 for(i=0;i<30;i++)
{

 System.out.println("Enter customer name : ");
 name = scan.next();
 System.out.prinln("Enter customer id :" );
 int custId= scan.nextInt();
 System.out.println("Enter number of purchases :");
 int numOfPurchases = scan.nextInt();
 System.out.println("Enter the city :");     
 city = scan.next();

Customer a.new Customer(name,custId,numOfPurchases,city);
listcustomer1.add(a);

 }

   int total =0,avg = 0;

   for(int i=0;i<listcustomer1.numOfPurchase;i++)
 {

   total= total+numOfPurchase;

   avg = total/listcustomer1;

   if(listcustomer1.numOfPurchase<10){

   listcustomer1.remove(i);

  Collections.copy(listcustomer2,i);
 }   

 }


  System.out.println("Customer Purchase Information ");
  System.out.println("Total number of purchases from all cities " +total());    
  System.out.println("Average number of purchase from all cities " +avg());

 }
 }  

运行后我收到了这个错误:

Customer.java:27: error: ';' expected
    Customer a.new Customer(name,custId,numOfPurchases,city);

缺少分号会出现此错误吗?我已经把但错误仍然存​​在。

3 个答案:

答案 0 :(得分:4)

从此行中删除.并添加=

Customer a.new Customer(name,custId,numOfPurchases,city); 

应该是:

Customer a = new Customer(name,custId,numOfPurchases,city);

答案 1 :(得分:1)

Customer a = new Customer(name,custId,numOfPurchases,city);

答案 2 :(得分:1)

replace dot with equals symbol 

Customer a.new Customer(name,custId,numOfPurchases,city);