zoukankan      html  css  js  c++  java
  • 动手动脑

    动手动脑1、

     编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数。

    import java.util.Random;
    import java.util.Scanner;
    public class TestSeed
    {
        public static void main(String[] args)
     {
           
            Random r = new Random(System.currentTimeMillis());
            System.out.println("请输入要得到多少随机数");
            int m;
            Scanner in = new Scanner(System.in);
            m = in.nextInt();
            for(int i=0;i<m;i++)
             System.out.println( r.nextInt());
            
        }
    }
    运行结果:
    请输入要得到多少随机数
    10
    1620020807
    -2070122496
    58291264
    742117536
    -1983758661
    -1649711892
    1181536659
    1091375721
    -870160946
    -1878357734

    动手动脑2、请看以下代码,你发现了有什么特殊之处吗?

    public class MethodOverload {
             public static void main(String[] args) {
                       System.out.println("The square of integer 7 is " + square(7));
                       System.out.println("
    The 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;
             }
    }
    运行结果:
    The square of integer 7 is 49
    
    
    The square of double 7.5 is 56.25
     

    满足以下条件的两个或多个方法构成重载关系:

    (1)方法名相同

    (2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。

  • 相关阅读:
    正敲着代码,鼠标坏了!
    DB2 OLAP函数的使用(转)
    修剪矩形
    classpath和环境变量设置(转)
    MyEclipse断点调试JavaScript浅析(转)
    Onunload和onbeforeunload方法的异同
    db2中的coalesce函数(转)
    db2:根据TABLEID找table
    [转]DB2行列转换
    DB2删除数据时的小技巧
  • 原文地址:https://www.cnblogs.com/MoooJL/p/11610497.html
Copyright © 2011-2022 走看看