2019.09.23 classroom summary

First, the hands-on brain 1

Write a method, using the above algorithm to generate a random integer to specify the number (such as 1000) of.

code show as below:

. 1  Import java.util.Scanner;
 2  
. 3  public  class the Random {
 . 4      Private  static Scanner SC = new new Scanner (the System.in);
 . 5  
. 6      public  static  void main (String [] args) {
 . 7          System.out.println ( "Please enter the desired number of random numbers generated: " );
 . 8          int n-= 0 ;
 . 9          n-= sc.nextInt ();
 10          System.out.println (" random number generated is: " );
 . 11          int X = 10 ;
 12 is          for ( int i = 1; i <= n; i++) {
13             x = (7 ^ 5 * x + 0) % 2147483647;
14             System.out.print(x + "\t");
15             if (i % 5 == 0) {
16                 System.out.println("");
17             }
18         }
19     }
20 }

Run shot:

 

 Second, the hands-on brain 2

Consider the following code, you find what is special about it?

 1 // MethodOverload.java
 2 // Using overloaded methods
 3 
 4 public class MethodOverload {
 5 
 6     public static void main(String[] args) {
 7         System.out.println("The square of integer 7 is " + square(7));
 8         System.out.println("\nThe square of double 7.5 is " + square(7.5));
 9     }
10 
11     public static int square(int x) {
12         return x * x;
13     }
14 
15     public static double square(double y) {
16         return y * y;
17     }
18 }
View Code

The above code shows the Java method override feature to meet two or more of the following methods constituting overload conditions relationship:

(1) The method of the same name;

Different (2) the number of parameters or different parameters or a different type order parameter type.

 

Guess you like

Origin www.cnblogs.com/best-hym/p/11588732.html