动手动脑

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

 

import java.util.Random;
import java.util.Scanner;
public class Make {
      public static void main(String[] args){
             Random rand=new Random();
             Scanner scan = new Scanner(System.in);
             int n;
             n = scan.nextInt();
             int x=rand.nextInt(100);
             for(int i=1;i<=n;i++)
             {
              x=(int) ((7^5*x+0)%(Math.pow(2,31)));
              System.out.print(x+" ");
              if(i%10==0)
               System.out.println();
             }
    }
}

 

结果

10
293 1470 7345 36722 183613 918070 4590345 22951722 114758613 573793070

 

 

方法重载

// 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("\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;
   }
}
 
 结果
The square of integer 7 is 49
The square of double 7.5 is 56.25
posted on 2019-09-25 12:41  嘻嘻_嘻  阅读(103)  评论(0编辑  收藏  举报