0
所以我试图调用一个方法displayBoard在java中显示一次用户输入一个数字,最初在主要方法中的桌面游戏。我无法调用这个方法。有没有人看到我要去哪里错了,或者我该如何解决这个问题?谢谢。方法调用问题Java
public static void displayBoard(int [] board, boolean showItem)
{
System.out.println();
System.out.print("_");
for (int val : board){
switch(codes){
case 2:
System.out.print("x");
break;
case 3:
System.out.print(" ");
break;
case 4:
System.out.print(showItem ? "Y" : " ");
break;
}
System.out.print("_");
} //for
System.out.println();
System.out.println();
}//display
public static void main (String [] args)
{
int guess = 0;
int userInput = promptForInt("Length Of board");
int [] numbers = new int[userInput];
int randomlocs = new Random().nextInt(userInput);
int val;
int display = displayBoard(board [], boolean showItem) // doesnt work?
boolean showItem = false;
while(! showItem)
{
val = promptForInt("Try Again!");
if(guess == randomlocation)
{
System.out.println("Found it!");
showItem = true;
}
else if(guess != randomlocs)
System.out.print(val);
}
}
谢谢您的回答,我明白的地方我现在去错了。目前我正在尝试此操作,并说“不兼容类型”。 – Zinconium 2014-11-01 07:17:27
@Zynk这是因为'displayBoard'是一个'void'方法,它不返回一个值。它应该是一个'int'方法,它返回一个整数,或者你不应该用它初始化一个变量,就像你使用'int display = displayBoard(int [],boolean)''一样。我看到它的方式,你不需要'int display'变量 – 2014-11-01 07:20:44
啊我看到了,它看起来不像我需要它,但是当我运行执行程序时,当用户升级为在promptForInt中的一个值,这就是为什么我认为我需要它。 谢谢你的帮助! :) – Zinconium 2014-11-01 07:25:11