随机数、方法重载和System.out.println()的理解

1.编写一个方法,使用以上算法生成指定数目(比如1000个)的随机数。

 1 package testradom;
 2 
 3 public class testradom {
 4     public static void main(String[] args) {
 5         long seed=System.currentTimeMillis();
 6         int Multiplier=16807,j=0;
 7         long random=(Multiplier*seed)%Integer.MAX_VALUE;
 8         for(int i=0;i<1000;i++) {
 9             random=(Multiplier*random)%Integer.MAX_VALUE;
10             System.out.print(random+" ");
11             j++;
12             if(j%10==0)System.out.println();
13         }
14     }
15 
16 }

2.请看以下代码,有什么特殊之处吗?

package cs;

public class MethodOverload {

    public static void main(String[] args) {
        System.out.println("The square of integer 7 is " + square(7));
        System.out.println("\nThe square of double 7.5 is " + square(7.5));
    }

    public static int square(int x) {
        return x * x;
    }

    public static double square(double y) {
        return y * y;
    }
}

 上述代码的特殊之处是关于方法的重载,是无法通过返回值的不同而进行区别的。

3.查看JDK中System.out.println()方法的部分内容 

out是system的成员变量;out在System类里面是PrintStream类型的的一个静态顶级成员变量,可以使用PrintStream里面的println方法。

转载于:https://www.cnblogs.com/quxiangjia/p/9789039.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值