我的问题有两个。 一个是我在尝试编译程序时收到一堆.class错误,我发现大多数其他问题都说缺少方括号是原因,但我所有的方括号都匹配。 两个在这种特定格式下的.class错误是什么?
代码:
class Simple
{
public static void main (String [] args)
{
boolean [] test1 = { false, true, true, true } ;
boolean [] test2 = { true } ;
boolean [] test3 = { true, true, true, true, false } ;
fullOfBool(boolean[] test1);
fullOfBool(boolean[] test2);
fullOfBool(boolean[] test3);
}
static void fullOfBool(boolean[] a)
{
for (int i = 0; i < a.length; i++)
{
if (a[i] == true)
{
System.out.println("The first true is at position" + i);
break;
}
}
for (int i = a.length - 1; i >= 0; i--)
{
if (a[i] == true)
{
System.out.println("The last true is at position" + i);
break;
}
}
}
}
我收到的错误:
Simple.java:12: error: '.class' expected
fullOfBool(boolean[] test1);
^
Simple.java:12: error: ';' expected
fullOfBool(boolean[] test1);
^
Simple.java:13: error: '.class' expected
fullOfBool(boolean[] test2);
^
Simple.java:13: error: ';' expected
fullOfBool(boolean[] test2);
^
Simple.java:14: error: '.class' expected
fullOfBool(boolean[] test3);
^
Simple.java:14: error: ';' expected
fullOfBool(boolean[] test3);
答案 0 :(得分:4)
这些陈述毫无意义:
fullOfBool(boolean[] test1);
fullOfBool(boolean[] test2);
fullOfBool(boolean[] test3);
仅尝试
fullOfBool(test1);
fullOfBool(test2);
fullOfBool(test3);