动手动脑以及课后实验性问题

一、随机数

import java.util.Random;


public class Suijishu {

   private static final int N = 200;

   private static final int LEFT = 40;

   private static final int RIGHT = 10000;

   private static long x0 = 1L;

   private long a = 1103515245L;

   private long c = 12345L;

   private long m = 2147483648L;

                       // 产生随机数

   private long rnd ( long r ){

       r = ( r * a + c ) % m; //Xn+1=(aXn + c)mod m
       return r;
   }

   private long little1 ( int a, int b, long rand ){

       return a+rand%(b-a+1);

   }

   private void recursion ( int count, long rand ){

         if (count >= N){return;}

   rand = rand (rand);

   long r = little1 (LEFT, RIGHT, rand);

   System.out.print (r + " ");

   recursion (++count, rand);

   }

   private long little(int left2, int right2, long rand) {
      // TODO Auto-generated method stub
      return 0;
   }

   public static void main ( String[] args ){

      Suijishu recur = new Suijishu ();
      recur.recursion (0, x0);

   }

}

二、方法重载

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;
   }
}

  满足以下条件的两个或多个方法构成“重载”关系:
    (1)方法名相同;
    (2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。
  注意:方法的返回值不作为方法重载的判断条件。

原文地址:https://www.cnblogs.com/zhangbaohai/p/5966168.html