小编Jes*_*a Z的帖子

扫描仪和字符串操作数类型不兼容?

我不断收到以下错误:

  • 扫描仪和字符串不兼容的操作数类型
  • 不兼容的操作数类型 int 和 String 在我添加 int op = Integer.valueOf(operator) 行之前,当我命名我的情况时,它一直给我错误。我还很新,这是我为我的课程编写的第二个代码,所以如果可能的话,请保持解释简单(如果对此有任何困惑,这里还没有显示一个计算器类):
//change the package name to calculatorClass///////////////

import java.util.Scanner;

public class assignmentB {

    public static String String(int y,int x, String name, String str) throws Exception {
        if (y < 1)
            throw new Exception("Value must be larger than 0.");
        if (x < 1)
            throw new Exception("Value must be larger than 0");
        return name;
        
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Calculator c1 = new Calculator(); …
Run Code Online (Sandbox Code Playgroud)

java string compiler-errors switch-statement java.util.scanner

1
推荐指数
1
解决办法
600
查看次数