刚入门中,提问下undefined for the type的问题。

本来学习过程中是尝试下构建一个负数的四舍五入的一个方法,但是总是报错。刚入门,帮我看下有什么问题。

public class MathPuls{
    double apr;
    public sswr(double apr){
        this.apr = apr;
        if(a > 0){
            return Math.floor(apr + 0.5);    
    }
        else{
            return Math.floor(apr - 0.5);
        }
    }
}



public class IntFunction {
    public static void main(String[] args) {
        // 经典数学四舍五入
        System.out.println("使用自己的方法四舍五入取整:" + MathPuls.sswr(-2.5));
    }
}


img


这个函数没有声明其返回值类型

你把第一个类的public去掉

一个程序中只能有一个主类

调用函数要类的成员才能调用,不能直接调用。先定义一个类成员吧