zoukankan      html  css  js  c++  java
  • java关于随机数和方法重构

    1.生成随机数

    源代码

    package Zuote;

     

    public class SuiJiShu {

        public static void main( String args[] )

        {

           java.util.Random r=new java.util.Random();

           for(int i=0;i<1000;i++)

           {

               System.out.println(r.nextInt(10)+1);

            }

        }

    }

    结果截图

     

    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;

        }

    }

    该代码特殊在函数的重载,不同类型相同函数名,当实参为int类型时调用int类型的函数,当实参为double类型时调用double类型的函数

  • 相关阅读:
    https协议介绍
    最详尽的fidder抓取https请求
    最详尽的datagrip使用
    datagrip安装与破解
    二叉树
    使用nexus搭建maven私库
    markdown利器-小书匠
    java开发-flyway
    .NetCore 入门
    .Net Core 实体生成器
  • 原文地址:https://www.cnblogs.com/aishanyishi/p/7651206.html
Copyright © 2011-2022 走看看