2023/09/20 动手动脑

 

package 示例;
import java.util.Random;
import java.util.Scanner;
public class thourandom {
     public static void main(String[] args) {

         Scanner sc=new Scanner(System.in);
         System.out.println("请输入你要生成随机数的数量");
         int n=sc.nextInt();
         for(int i=0;i<n;i++)
         {
             System.out.println(getrandom());
         }
        }
        
        public static int getrandom() {        
            Random _random = new Random();
            
            return _random.nextInt();
        }
}

 

 

public class MethodOverload {

    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(double y) {
        return y * y;
    }
}

同名方法中系统会根据参数的类型,数量,类型的组合来调用不同的方法

系统并不会根据方法的返回值种类掉用函数

posted @ 2023-09-20 21:57  伐木工熊大  阅读(30)  评论(0)    收藏  举报