java - 错误 : '.class' expected

标签 java class

<分区>

friend 们好,编译时出现以下错误

错误:应为“.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”来编译程序

最佳答案

您在 isGoodEmployee 中有一个不匹配的方法调用。

childnames 参数被定义为一个数组,所以你可以简单地传入参数,替换:

t.isGoodEmployee(ismarried,noofchild,middlename,childnames[]);

t.isGoodEmployee(ismarried,noofchild,middlename,childnames);

除此之外,不要忽略其他编译器错误,例如

middlename.endssWith("e");
               ^---------extra 's'

熟悉 javadocs .

关于java - 错误 : '.class' expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14110171/

相关文章:

c++ - 如何处理类中的动态分配变量?

python - 如何在Python中另一个类的方法中引用函数的 "return"?

java - 将 PGP(公共(public)) key 存储在 java keystore 中 - BouncycaSTLe

java - 在不重新分配原始字符串值的情况下将 int 的值压入字符串

java - 无法找到或加载主类

javascript - 内置类的子类的私有(private)字段在被覆盖的方法中是否不可访问?

php - PHPs IteratorAggregate 中 getIterator 返回的数组不可遍历

java - 正确引用对象

java - web.xml中如何通过URL传递参数?

ios - 从另一个类更新 UILabel