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

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

     1 package testradom;
     2 
     3 public class testradom {
     4     public static void main(String[] args) {
     5         long seed=System.currentTimeMillis();
     6         int Multiplier=16807,j=0;
     7         long random=(Multiplier*seed)%Integer.MAX_VALUE;
     8         for(int i=0;i<1000;i++) {
     9             random=(Multiplier*random)%Integer.MAX_VALUE;
    10             System.out.print(random+" ");
    11             j++;
    12             if(j%10==0)System.out.println();
    13         }
    14     }
    15 
    16 }

    2.请看以下代码,有什么特殊之处吗?

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

     上述代码的特殊之处是关于方法的重载,是无法通过返回值的不同而进行区别的。

    3.查看JDK中System.out.println()方法的部分内容 

    out是system的成员变量;out在System类里面是PrintStream类型的的一个静态顶级成员变量,可以使用PrintStream里面的println方法。

  • 相关阅读:
    codevs 3971 航班
    2015山东信息学夏令营 Day4T3 生产
    2015山东信息学夏令营 Day5T3 路径
    Tyvj 1221 微子危机——战略
    清北学堂模拟赛 求和
    NOIP2012同余方程
    NOIP2009 Hankson的趣味题
    bzoj1441 MIN
    国家集训队论文分类
    贪心 + DFS
  • 原文地址:https://www.cnblogs.com/quxiangjia/p/9789039.html
Copyright © 2011-2022 走看看