Eclipse Error"语法错误,插入"。类"完成ArgumentList"

时间:2014-12-15 04:39:29

标签: java

我不断收到此错误消息:

错误:语法错误,插入“.class”以完成ArgumentList

我该如何解决? 插入其他单词因为stackoverflow不会让我发布这个否则

import java.util.Scanner; 
import java.io.*; 

public class javahw5_11
{
  public static void main(String [] args)
  {
    Scanner keyboard = new Scanner(System.in); 

    int saleData[] = new int[5];  

    System.out.print("How many shares are you buying?"); 
    saleData[0] = keyboard.nextInt(); 
    System.out.print("What is the purchase price per share?"); 
    saleData[1] = keyboard.nextInt(); 
    System.out.print("How much was the sales price per share?"); 
    saleData[2] = keyboard.nextInt(); 
    System.out.print("How much is the purchase commission?"); 
    saleData[3] = keyboard.nextInt(); 
    System.out.print("How much was the sales commission?"); 
    saleData[4] = keyboard.nextInt(); 

    double profit = getProfit(saleData[]); 
    System.out.print("Your profit is "+profit); 

    keyboard.close(); 
  }

  public static double getProfit(int saleData[])
  {
    double profit = (((saleData[0]*saleData[2])-saleData[4])-((saleData[0]*saleData[1])+saleData[3]));
    return profit; 
  }

}

3 个答案:

答案 0 :(得分:0)

注意salesData[3]salesData不存在。将其更改为saleData

另请注意double profit = getProfit(saleData[]);。当您将其作为参数传递时,从saleData移除括号。

答案 1 :(得分:0)

几个错误。

1。)将double profit = getProfit(saleData[]);更改为double profit = getProfit(saleData);。只需要传递参考saleData

2。)在salesData

中使用saleData代替double profit = (((saleData[0] * saleData[2]) - saleData[4]) - ((saleData[0] * saleData[1]) + salesData[3]));

答案 2 :(得分:0)

将其更改为以下语句..您已在代码

中指定为salesData [3]

double profit =((saleData [0] * saleData [2]) - saleData [4]) - ((saleData [0] * saleData [1])+ saleData [3]));