如何给这个程序添加一个main方法?

您好,我对编码相当陌生,不明白我必须完成的所需任务。如何通过添加 main 方法来运行以下代码以确保其正常工作?


答案和文件将非常有帮助,谢谢。


public static boolean approxEqual (double x, double y)

{

        //Judge where two numbers are close enough (equal)

        final double EPSILON = 1E-10;

        if (Math.abs(x-y)<EPSILON)

        {

            return(true);

        }

    return(false);

}


红糖糍粑
浏览 86回答 1
1回答

万千封印

您可以声明一个类并向其添加 main 方法,如下所示public class Sol {&nbsp; &nbsp; public static void main(String[] args) {&nbsp; &nbsp; &nbsp; &nbsp; Sol.approxEqual(1.0,1.2)&nbsp; &nbsp; }&nbsp; &nbsp; public static boolean approxEqual (double x, double y)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; //Judge where two numbers are close enough (equal)&nbsp; &nbsp; &nbsp; &nbsp; final double EPSILON = 1E-10;&nbsp; &nbsp; &nbsp; &nbsp; if (Math.abs(x-y)<EPSILON)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return(true);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return(false);&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java