-4

我在公共静态无效行中不断收到错误,并且 system.out 输入您的年销售额。我要做的是让用户输入年销售额,然后通过考虑固定工资和佣金来获得年销售额:

import java.util.Scanner;
import java.io.BufferedReader;

public class commission {

    public static void main(String[] args)

            Scanner input = new Scanner( System.in; 
            BufferReader br = new BufferReader(instream);

            System.out.println("Enter your annual sales");
            String annual = br.readLine();

            int salary = 75_502_81; 
            int com = 38_28; 
            int compensation = annual * com + salary;

}
4

5 回答 5

0

直接的问题是缺少左大括号 ( {) 和右括号 ( ))

public static void main(String[] args) {
                                       ^--- This is important...
    Scanner input = new Scanner( System.in); 
                                          ^--- Also important :P
    BufferReader br = new BufferReader(instream);

    System.out.println("Enter your annual sales");
    String annual = br.readLine();

    int salary = 75_502_81; 
    int com = 38_28; 
    int compensation = annual * com + salary;
}

没有这样的课程BufferReader,我想你的意思是BufferedReader

你的代码中没有instream声明这样的变量,我想你可能的意思是input,但BufferedReader不会input作为有效的输入类型,所以我不确定你的意图是什么......

您还将收到有关未捕获的警告IOException

您可以通过使用解决这些问题try-catch

我也很好奇什么75_502_81和应该是什么38_28意思? intvalues 不能包含除数值以外的任何内容...

annualis also String,这意味着您不能对其执行任何数学运算。

您需要将值转换为int第一个...

public static void main(String[] args) {

    Scanner input = new Scanner( System.in ); 
    BufferedReader br = null;

    try {
        br = new BufferedReader(instream);
        System.out.println("Enter your annual sales");
        String annual = br.readLine();

        int salary = 7550281; 
        int com = 3828; 
        int compensation = Integer.parseInt(annual) * com + salary;

    } catch (IOException exp) {
        exp.printStackTrace();
    } finally {
        try {
            br.close();
        } catch (Exception exp) {
        }
    }
}

但我不知道为什么,什么时候

public static void main(String[] args) {

    Scanner input = new Scanner( System.in ); 
    System.out.println("Enter your annual sales");
    String annual = input.nextLine();

    int salary = 7550281; 
    int com = 3828; 
    int compensation = Integer.parseInt(annual) * com + salary;

}

会做同样的事情...

于 2013-10-21T04:31:27.227 回答
0

你不能这样做

int compensation = annual * com + salary;

因为每年是一个字符串 :) 你必须将字符串解析为整数,也许像这样

Integer.parseInt(annual);

希望能帮助到你 :)

于 2013-10-21T04:37:56.753 回答
0

您的代码中有几个问题:

当前错误的原因是您缺少right paren. And a left brace@Makoto 评论。

尝试这个:

public static void main(String[] args) {
    Scanner input = new Scanner( System.in); 
    System.out.println("Enter your annual sales");

    int annual = Integer.parseInt(input.nextLine());
    int salary = 75_502_81; 
    int com = 38_28; 
    int compensation = annual * com + salary;
    System.out.println(compensation);
}
于 2013-10-21T04:41:41.207 回答
0

也缺少右括号

Scanner input = new Scanner( System.in);<----- 

而且我不确定扫描仪对象是否与缓冲阅读器一起使用,它需要一个阅读器对象

于 2013-10-21T04:41:54.413 回答
0

语法错误很少。试试下面的代码,它必须解决问题。

public class Commission {

    public static void main(String[] args) { 
            Scanner input = new Scanner( System.in); 
            System.out.println("Enter your annual sales");
            String annual = input.nextLine();

            int salary = 75_502_81; 
            int com = 38_28; 
            int compensation = Integer.parseInt(annual) * com + salary;
            System.out.println("compensation is: "+compensation );
    }
}
于 2013-10-21T04:53:11.620 回答