课程作业·02

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

package suijishu;
import java.util.Scanner;
public class suijishu {

public static void main(String[] args) {
// TODO Auto-generated method stub
int value;
String output = "";
Scanner in=new Scanner(System.in);
System.out.print("请输入生成随机数的数量:");
int n=in.nextInt();
for ( int i = 1; i <= n; i++ ) {
value = 1 + (int) ( Math.random() * 10 );
output += value + " ";
if ( i % 10 == 0 )
output += " ";
}
System.out.print( output);
System.exit( 0 );
}

}

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

代码中两个方法 方法名相同· 返回值类型·和参数类型不同 此为方法的重载

原文地址:https://www.cnblogs.com/zhpdqs/p/7663471.html