1,编写一个方法,使用算法生成指定数目(如1000个)的随机整数
package pers.liqin.suiji.lq; import java.util.Scanner; public class SuiJi { public long a=3421L; public long c=1234L; public long m=1267L; public long x=1; public long zhengshu() { x=(x*a+c)%m; return x; } public static void main(String[] args ) { System.out.println("请输入生成的随机整数的个数:"); Scanner s=new Scanner(System.in); int n=s.nextInt(); SuiJi m=new SuiJi(); long h; for(int i=0;i<n;i++) { h=m.zhengshu(); System.out.println("x:"+h); } } }
截图:
2,请看以下代码,你发现了有什么特殊之处吗?
public class MethodOverload { public static void main(String[] args) { System.out.println("The square of integer 7 is " + square(7)); System.out.println(" The 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; } }
运行结果:
运用了System.out.println()的重载
3,查看一下JDK中System.out.println()方法,你发现了什么?