动手又动脑

信1605-3 于丁一 20163578 
求平方数的静态类方法Square.java,不用static但仍想在main中调用的处理方法。
public class number {
    public static void main(String[] args) {    
        for (int  x=1; x <= 10; x++) {
            SquareIntTest obj;  
            obj=new SquareIntTest();
              int result = obj.square(x);
            // result=(int)Math.pow(x,2);
            System.out.println("The square of " + x + " is " + result + "
");
        }
    }
    public int square(int y) {        
        return y * y;
    }
}

结果:

 计算7^2时,调用的是整型

而计算7.5^2时,调用的是双精度类型

注意:方法的返回值不作为方法重载的判断条件。

 查看一下JDK中System.out.println()方法,你发现了什么? 

CalculateN示例程序中的BUG,50!出现负数。

原因:计算机能处理的数值是有一定限度的,如果你超过了这一限度,计算机输出的结果会以二进制的形式来表达。

原文地址:https://www.cnblogs.com/ydy1/p/7659254.html