1.方法重载

我发现同名函数可以重载从而实现不同的类型的运算。
满足以下条件的两个或多个方法可以构成“重载”关系:
(1)方法名相同;
(2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。
注意:方法的返回值不可以作为方法重载的判断条件。
2.完全“手写代码实现”随机数生成
例:在范围0~1000中生成20个随机数
1 package 生成随机数;
2 public class Suiji {
3 private static final int N = 20;//生成随机数的个数
4 private static final int LEFT = 0;//生成随机数的左范围
5 private static final int RIGHT = 1000;//生成随机数的右范围
6 private static long x0 = 1L;
7 private long a = 1234567890L;
8 private long c = 12345L;
9 private long m = 2345678912L;
10 // 产生随机数
11 private long rand ( long r )
12 {
13 // a,c,m为常数
14 r = ( r * a + c ) % m;//Xn+1=(aXn + c)mod m
15 return r;
16 }
17 private long little ( int L, int R, long rand ){
18 return L + rand % ( R - L + 1 );
19 }
20 int jishu=1;
21 private void recursion ( int count, long rand ){
22 if (count >= N) {
23 return;
24 }
25 rand = rand (rand);
26 long r = little (LEFT, RIGHT, rand);
27 System.out.print (r + " ");
28 recursion (++count, rand);
29 }
30 public static void main(String[] args) {
31 Suiji a = new Suiji ();
32 a.recursion (0, x0);
33 }
34 }
3.查看JDK中System.out.println()方法的部分内容
1 /** 2 * Prints an integer and then terminate the line. This method behaves as 3 * though it invokes <code>{@link #print(int)}</code> and then 4 * <code>{@link #println()}</code>. 5 * 6 * @param x The <code>int</code> to be printed. 7 */ 8 public void println(int x) { 9 synchronized (this) { 10 print(x); 11 newLine(); 12 } 13 } 14 /** 15 * Prints a String and then terminate the line. This method behaves as 16 * though it invokes <code>{@link #print(String)}</code> and then 17 * <code>{@link #println()}</code>. 18 * 19 * @param x The <code>String</code> to be printed. 20 */ 21 public void println(String x) { 22 synchronized (this) { 23 print(x); 24 newLine(); 25 } 26 }