随机生成自己想要个数的数字
package shangke.disanzhou; import java.util.Random; import java.util.Scanner; public class dongshoudongnao { public static void main(String[] args) { long a,b,n; Scanner shuru=new Scanner(System.in); n=shuru.nextInt(); Random R = new Random(); a=R.nextInt(); b= Integer.MAX_VALUE; for(int i=0;i<n;i++) { a=(a*16807)%b; System.out.println(a); } } }
可根据自己需要选择数量打印随机数
package shangke.disanzhou; //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(" 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; } }
这个函数是对函数重载的一种利用方法,函数参数类型不同,参数个数不同,或者参数类型顺序不同都可以进行函数的重载