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

 

import java.util.*;

public class Random {
    public static void main( String [] args ){
        Random rand = new Random();
        Scanner in = new Scanner( System.in );
        int number;
        System.out.println("请输入生成的随机数数量");
        number = in.nextInt();
        for( int i=0; i<number; i++){
            System.out.println(rand.nextInt());
        }
    }
}

 

请看以下代码,你发现了有什么特殊之处吗?

// MethodOverload.java
// Using overloaded methods

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;
    }
}

参数类型不同可以构成“重载”关系

 

posted on 2018-10-14 17:54  墨钺  阅读(98)  评论(0编辑  收藏  举报