Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
567 views
in Technique[技术] by (71.8m points)

java - 为什么会发生此错误? (不兼容的类型:int不能转换为int [])(Why this error is happening? (incompatible types: int cannot be converted to int[]))

When I try to print variable b in this method, I face an error.

(当我尝试使用此方法打印变量b时,遇到错误。)

I didn't initialize the variable b as an array , why this is happening?

(我没有将变量b初始化为array ,为什么会发生这种情况?)

public void print(int[] data){
   int b = 2;
   print(b);
}

This is the error I get : incompatible data type : int cannot be converted to int[]

(这是我得到的错误: 不兼容的数据类型:int无法转换为int [])

  ask by ??? translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're own method is named print and takes an int[] .

(您自己的方法名为print并且需要一个int[] 。)

Option one:

(选项一:)

Change

(更改)

print(b);

to

(至)

System.out.println(b);

Option two:

(选项二:)

Add a print(int) method

(添加一个print(int)方法)

public static void print(int v) {
    System.out.println(v);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...