小编For*_*ure的帖子

静态方法中的 if/else 语句问题

package geometrypack;

public class Calc {
    public static double areaOfCircle(int radius) {
        if (radius <= 0) {
            System.out.println("Input cannot be a negative number.");
        }
        return (Math.PI * (radius * radius));
        
    } // areaOfCircle method
    
    public static double areaOfRectangle(int length,int width) {
        if (length <= 0 || width <= 0) {
            System.out.println("Input cannot be a negative number.");
        }
        return length * width;
        
    } // areaOfRectangle method
    
    public static double areaOfTriangle(int base, int height) {
        if (base <= 0 || height <= …
Run Code Online (Sandbox Code Playgroud)

java static-methods conditional-statements

1
推荐指数
1
解决办法
845
查看次数