1.生成随机数
源代码
package Zuote;
public class SuiJiShu {
public static void main( String args[] )
{
java.util.Random r=new java.util.Random();
for(int i=0;i<1000;i++)
{
System.out.println(r.nextInt(10)+1);
}
}
}
结果截图
2.以下代码的特殊之处
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;
}
}
该代码特殊在函数的重载,不同类型相同函数名,当实参为int类型时调用int类型的函数,当实参为double类型时调用double类型的函数