zoukankan      html  css  js  c++  java
  • 2019年9月23日动手动脑

    一、MethodOverload

    (1)题目

    (2)源代码

    // MethodOverload.java
    // Using overloaded methods
    
    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;
        }
    }
    MesthodOverload

    (3)输出结果

    (4)分析

       同名的方法,不同的参数数量、不同的参数类型、不同的参数顺序都可以重载。

     二、生成随机数

    (1)题目

    (2)源代码

    import java.util.*;
    public class Test2Random {
        public static void main(String[] args) {
            Scanner n=new Scanner(System.in);
            int input=n.nextInt();
            Random ran = new Random(System.currentTimeMillis() );
            for(int i=1;i<=input;i++) {
                System.out.print(ran.nextInt()+"\t");
                if(i%5==0)
                    System.out.println();
            }
            n.close();
        }
        
    }
    TestRandom

    (3)输出结果

  • 相关阅读:
    bzoj4734
    51nod1056
    51nod1048
    51nod1248
    51nod1044
    51nod1132
    51nod1146
    51nod1226
    Spring Boot: Jdbc javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
    sqlserver命令创建数据库和表 demo
  • 原文地址:https://www.cnblogs.com/suanai/p/11595009.html
Copyright © 2011-2022 走看看