First, the hands-on brain 1
1. Topic
2. Source Code
. 1 Package yang8; 2 . 3 Import java.util.Scanner; . 4 Import java.util.Random; . 5 . 6 public class shengchengsuiji { . 7 public static void main (String [] args) { . 8 // instantiate the object . 9 the Random RAND = new new the random (); 10 Scanner iNPUT = new new Scanner (the System.in); . 11 System.out.println ( "Please enter the number of generated random numbers:" ); 12 is int NUM = input.nextInt (); 13 is System.out.println ( "Please enter the number of prints per row random number:" ); 14 int n-= input.nextInt (); 15 int J = 0 ; 16 // randomly generated between a seed 0-100 . 17 int SEED = rand.nextInt (99) + 1'd ; 18 is // cycle times num . 19 for ( int I = 0; I <num; I ++ ) 20 is { 21 is // generates a random number using pure random number generator 22 is SEED = ( SEED + 0 * 16807)% 2147483647 ; 23 is J ++ ; 24 IF (% n-J == 0 ) { 25 System.out.println ( "\ n-" ); 26 is } 27 of System.out.print (+ SEED "\ T" ); 28 } 29 System.out.println ( "\ n-" ); 30 // output message 31 System.out.println ( "complete generation" ); 32 } 33 }
3. Run results
Second, the hands-on brain 2
1, title
Consider the following code, you find what is special about it?
1 // MethodOverload.java 2 // Using overloaded methods 3 4 //***函数重载*** 5 public class MethodOverload { 6 7 public static void main(String[] args) { 8 System.out.println("The square of integer 7 is " + square(7)); 9 System.out.println("\nThe square of double 7.5 is " + square(7.5)); 10 } 11 12 public static int square(int x) { 13 return x * x; 14 } 15 16 public static double square(double y) { 17 return y * y; 18 } 19 }
2. Answers
Found: two functions the same method name, the same functionality, but with different parameter types two methods.
Cause: This is the method java overloaded, overload conditions as the method name of the method is the same value, but the order of the different types of process parameters, the number of parameters, parameter types to meet one or more,
It is called method overloading.
Third, after-school experiment
1. Topic
Look at the JDK System.out.println () method, what have you found?
2. Found
There are many JDK overloaded method System.out.println () with the same name.
3. Cause
To make the code easier to write when different types of data output, so the output method with the same name are overloaded or method overloading.