嗨,朋友们,编译下面的错误即将到来
错误:应为'.class‘
我找不到错误是什么。我查看了很多网站,但都不能找到为什么会出现这个错误。请帮助
提前谢谢。
import java.io.*;
class Test
{
boolean isGoodEmployee(boolean ismarried,int noofchild,String middlename,String childnames[])
{
boolean child,letter,last,child;
if (noofchild <= 2)
child=true;
boolean firstletter = middlename.startsWith("k");
boolean lastletter = middlename.endssWith("e");
if (firstletter && (!lastletter))
letter = true;
int lastnameletterscount = lastname.length();
if (lastnameletterscount > 4)
last = true;
String name = raju;
for (int i=0; i < noofchild; i++)
if(name.equalsIgnoreCase(childnames[i]))
{
child = true;
break;
}
}
}
class GoodEmployee
{
public static void main(String args[]) throws IOException
{
String firstname, middlename, lastname;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the first name of employee");
firstname = br.readLine();
System.out.println("enter the middle name of employee");
middlename = br.readLine();
System.out.println("enter the last name of employee");
lastname = br.readLine();
//System.out.println("full name of employee is:"+first+middle+last);
System.out.println("enter employee is married or not");
boolean ismarried = Boolean.parseBoolean(br.readLine());
if (ismarried)
System.out.println("enter number of childrens");
int noofchild = Integer.parseInt(br.readLine());
String childnames[] = new String[noofchild];
System.out.println("enter children names");
for (int i=0; i < noofchild; i++)
childnames[i] = br.readLine();
Test t = new Test();
t.isGoodEmployee(ismarried,noofchild,middlename,childnames[]);
}
}
我使用"javac GoodEmployee.java“来编译这个程序。
发布于 2013-01-01 19:58:15
在isGoodEmployee
中有一个不匹配的方法调用。
childnames
参数被定义为一个数组,因此您可以简单地传入参数replace:
t.isGoodEmployee(ismarried,noofchild,middlename,childnames[]);
使用
t.isGoodEmployee(ismarried,noofchild,middlename,childnames);
除此之外,不要忽略其他编译器错误,例如
middlename.endssWith("e");
^---------extra 's'
熟悉javadocs。
发布于 2013-01-01 19:58:00
这段代码有很多错误:
您已经在isGoodEmployee() (第1行)中声明了两次布尔子级
endssWith应为endsWith()
以此类推,但它们都不是您所说的问题。你使用什么命令行来编译这个类?
发布于 2013-01-01 20:50:40
@Reimeus已经做到了。
奇怪的编译错误可以解释如下。在这一行中:
t.isGoodEmployee(ismarried,noofchild,middlename,childnames[]);
childnames[]
短语应该是一个Java表达式。但实际上,它的语法最接近于一个类型...实际上,一个称为childnames
的(不存在的)类组成的数组。Java编译器的语法错误恢复代码决定,如果它在typename (即childnames[].class
)之后插入.class
,将会给出一个语法上有效的表达式。
当然,编译器建议的更正是毫无意义的……尤其是因为在您的应用程序中不会有一个名为childnames
的类或接口。
这个故事的寓意是,不寻常的语法错误有时会导致编译器产生特殊的错误消息,只有当您能弄清楚解析器如何解析错误的输入时,这些消息才有意义。
https://stackoverflow.com/questions/14110171
复制相似问题