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

    }

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

                ①方法名相同

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

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

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



  • 相关阅读:
    基于spec评论作品
    Alpha版发布
    软件工程第七次作业
    软件工程第六次作业
    软件工程第五次作业
    django-rest-framework笔记-序列化篇
    django restframework系列笔记
    rpyc 文件监控
    python subprocess select 读取
    Python 多线程 类和方法
  • 原文地址:https://www.cnblogs.com/Aming-/p/11597367.html
Copyright © 2020-2023  润新知