• 随机数、方法重载和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方法。

  • 相关阅读:
    MATLAB 高斯金字塔
    MATLAB 灰度图直方图均衡化
    MATLAB 生成高斯图像
    MATLAB 灰度、二值图像腐蚀膨胀
    MATLAB 中值滤波
    MATLAB 最大中值滤波
    MATLAB 最大均值滤波
    MATLAB 图像加噪,各种滤波
    MATLAB 图像傅里叶变换,幅度谱,相位谱
    十款最佳人工智能软件
  • 原文地址:https://www.cnblogs.com/quxiangjia/p/9789039.html
Copyright © 2020-2023  润新知