zoukankan      html  css  js  c++  java
  • 关于随机数、方法重载和System.out.println()的认识

    (1)使用纯随机数发生器编写一个指定数目内数字的程序(类真随机数)

    源代码:

    package Demo1;
    
    public class trueRandom {
        long Multiplier = 45826L;
        long Increment = 75369L;
        long Modulos = 78654L;
        long r = 0;
        public long rand(){
            r = (Multiplier*r+Increment)%Modulos;
            return r;
        }
        public static void main(String[] args){
            trueRandom s=new trueRandom();
            long r;
            for(int i=1;i<1000;){//输出1000个随机数
                r=s.rand();
                System.out.print(r+" ");
                i++;
                if (i%20==0)//每输入20个换行
                    System.out.println("");
                }
            }
    }

    运行结果:

    (2)System.out.println() 

     根据Jdk API 1.6.0版显示:

    1、System类java.lang包中的一个,继承于Object类。

    2、在System类中,out是PrintStream类中的一个静态成员变量,所以可以用类名.变量名引用。(API显示:out是“标准”输出流。此流已打开并准备接受输    出数据。通常,此流对应于显示器输出或者由主机环境或用户指定的另一个输出目标。)

    3、println()是PrintStream的一个方法,被out调用。

    (3)方法重载

     1 package Demo1;
     2 
     3 public class MethodOverload {
     4     public static void main(String[] args) {
     5         System.out.println("The square of integer 7 is " + square(7));
     6         System.out.println("
    The square of double 7.5 is " + square(7.5));
     7     }
     8 
     9     public static int square(int x) {
    10         return x * x;
    11     }
    12 
    13     public static double square(double y) {
    14         return y * y;
    15     }
    16 }

     

    java允许在同一范围中声明几个功能类似的同名函数,但这些同名函数的形式参数(参数的个数,类型或顺序)必须不同,称之为函数的重载。
  • 相关阅读:
    从B树、B+树、B*树谈到R 树
    The Log-Structured Merge-Tree(译)
    Leveldb源码分析--2
    Leveldb源码分析--1
    little-endian And big-endian
    Fixed数据类型
    Varint数值压缩存储方法
    JavaEE开发之SpringBoot工程的创建、运行与配置
    Javaee基本框架(Struts2,Spring,MyBatista)之间的关系
    XLM解析技术概述
  • 原文地址:https://www.cnblogs.com/YXSZ/p/9786900.html
Copyright © 2011-2022 走看看