01Java- method

A: hands-on brain

1. Write a method, using the above algorithm for generating a specified number (such as 1000) of random integers

Package Reserve;
 Import java.util.Scanner;
 Import java.util.Arrays;
 Import java.util.Random; 

public  class the Main {
     public  static  void main {(String [] args) 
        the Random Random = new new the Random (); 
        Scanner SC = new new Scanner (the System.in); 
        System.out.println ( "Please enter the number of generated random numbers:" );
         int COUNT = sc.nextInt ();
         byte [] Buffer = new new  byte [COUNT]; 
        random.nextBytes (buffer);
        System.out.println(Arrays.toString(buffer));
    }
}

2. Take a look at the code, you find anything special about it?

package reserve;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;

public class Main{
    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(doubley) {
         return y * y; 
    } 
}

Code test shots:

 

 Overload demonstrated in Java, a method (the same method name, parameter types, the number of different parameters, or parameter sequence)

Only the calculated results to determine the type. (The return value as a determination condition is not overloaded method)

Guess you like

Origin www.cnblogs.com/hhjing/p/11581908.html