zoukankan      html  css  js  c++  java
  • Java课02

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

    package cn.demo5;

    import java.util.*;
    import java.util.Scanner;

    public class Random {
        static Scanner in=new Scanner(System.in);
        
        static public void Seed(long seed)
        {
            Random rand=new Random();
            long a,x=0,x1;
            System.out.println("请输入想要产生的随机数的个数");
            a=in.nextLong();
            for(long i=1;i<=a;i++)
            {
                x1=(16800*seed)%(Integer.MAX_VALUE);
                System.out.println(x1);
                x++;
                if(x<=(2e+32)-2)
                    seed=x1;
                else
                    seed=rand.nextLong();
            }
            
        }
        public static void main(String []args)
        {
            long b;
            System.out.println("请输入想要输入的种子");
            b=in.nextLong();
            Seed(b);
        }
    }

    2.重载

    package cn.demo4;

    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;
        }

    }

    满足以下两个条件即可构成函数重载

                ①方法名相同

                ②参数类型不同,参数个数,参数类型的顺序不同

     注意:函数的返回值类型不能作为函数重载的判断条件。

                因为在运行时,一开始并不知道所调用的函数返回值是什么,一开始只会根据参数的类型去寻找对应的函数



  • 相关阅读:
    超级小白使用pip安装第三方库的正确姿势
    selenium+python自动化测试--解决无法启动IE浏览器及报错问题
    microsoft edge浏览器安装驱动
    超详细MySQL安装及基本使用教程
    Navicat15最新版本破解 亲测可用!!!
    Ubuntu 16.04安装JMeter测试工具
    JMeter_Ubuntu上安装jmeter
    韩国vps推荐-kdatacenter
    全栈之js入门篇
    Web前端之CSS_day5
  • 原文地址:https://www.cnblogs.com/Aming-/p/11597367.html
Copyright © 2011-2022 走看看