编写java文件

时间:2013-10-21 04:30:01

标签: java

我一直在公共静态空行中出错,而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;

}

5 个答案:

答案 0 :(得分: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_8138_28是什么意思? int值不能包含除数值之外的任何内容...

annual也是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;

}

会做同样的事情......

答案 1 :(得分:0)

你不能这样做

int compensation = annual * com + salary;

因为year是一个String :)你必须将String解析为Integer,也许就像这样

Integer.parseInt(annual);

希望有所帮助:)

答案 2 :(得分: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);
}

答案 3 :(得分:0)

也是一个缺少的大括号

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

我不确定扫描仪对象是否配有bufferedreader,它需要一个读者对象

答案 4 :(得分: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 );
    }
}