Java 为什么程序会给出“非法启动类型”错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2448768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does the program give "illegal start of type" error?
提问by David
here is the relevent code snippet:
这是相关的代码片段:
public static Rand searchCount (int[] x)
{
int a ;
int b ;
int c ;
int d ;
int f ;
int g ;
int h ;
int i ;
int j ;
Rand countA = new Rand () ;
for (int l= 0; l<x.length; l++)
{
if (x[l] = 0)
a++ ;
else if (x[l] = 1)
b++ ;
}
}
return countA ;
}
(Rand is the name of the class that this method is in)
(Rand 是此方法所在的类的名称)
when compiling it get this error message:
编译时收到此错误消息:
Rand.java:77: illegal start of type
return countA ;
^
what's going wrong here? what does this error message mean?
这里出了什么问题?这个错误信息是什么意思?
采纳答案by codaddict
You have a misplaced closing brace before the return
statement.
在return
语句之前有一个错位的右大括号。
回答by Neeraj Kumar
You have an extra '{' before return type. You may also want to put '==' instead of '=' in if and else condition.
在返回类型之前有一个额外的“{”。您可能还想在 if 和 else 条件中放置 '==' 而不是 '='。