10.4动手动脑
方法的重载:
public static int square(int x)
{
return x * x;
}
public static double square(double y)
{
return y * y;
}
The square of integer 7 is 49
The square of double 7.5 is 56.25
方法在使用的时候会出现根据所给的参数决定该调用哪个函数
import java.util.Scanner;
public class Random {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.print("输入你要获取的随机数个数:");
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();//获取的随机数的个数
for(int i = 0;i < n;i++)//for循环
System.out.println((int)(Math.random()*1000));
//输出获取的1-10000的随机数
}
}