猿问

尽管我的代码返回String,但该函数仍希望返回字符串

//即使返回成功消息后,我仍然会得到String return期望... //任何帮助将不胜感激


public String addStudent(Student student) throws Exception 

{

    try

    {

        Validator validate = new Validator();

        validate.validate(student);

        if((student.getMark1()<50 && student.getMark2()<50 && student.getMark3()<50) && student.getResult()=='P')

            throw new Exception("Service.INVALID_RESULT_PASS");

        if((student.getMark1()>=50 || student.getMark2()>=50 || student.getMark3()>=50) && student.getResult()=='F')

            throw new Exception("Service.INVALID_RESULT_FAIL");

        return "Success";

    }

    catch(Exception e)

    {

        System.out.println(e.getMessage());

    }

}


翻阅古今
浏览 156回答 2
2回答
随时随地看视频慕课网APP

相关分类

Java
我要回答