zoukankan      html  css  js  c++  java
  • 动手动脑

    动手动脑一:纯随机数发生器

    源代码:

    package Test;
    import java.util.Random;
    public class Test {
     public static void main(String[] args) {
      Random r = new Random(1000);
      int Modulus  = 2<<(30)-1 ;
      int Multiplier = 16807;
      int C = 0;
      int x = r.nextInt();
      for(int i=0;i<1000;i++) {
       x = (Multiplier*x+C)%Modulus;
       System.out.println(x+" ");
      }
     }
    }
    运行结果:

    动手动脑二:java方法的重载

     源代码:

    // MethodOverload.java
    // Using overloaded methods
    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;
     }
    }
    特殊之处:具有相同的方法名,参数类型不同,形成了java方法的重载

     java方法重载条件:

    1.方法名相同

    2.参数类型不同,参数个数不同,参数类型的顺序不同

    注意:方法的返回值不能作为方法重载的判断条件

    在JDK中System.out.println()源码:

        public void println(String x) {
            synchronized (this) {
                print(x);
                newLine();
            }
        }

    同样也是方法。

  • 相关阅读:
    Android Studio 插件
    天气预报接口api(中国天气网)
    使用easyui的Tree 实现无限子节点绑定
    js调用后台方法
    div窗口效果来自标准之路
    C#生成dll程序集文件
    一个技术人的博客
    HTML-embed标签详解
    网站生成桌面快捷图标
    文本框宽度自动适应文本宽度
  • 原文地址:https://www.cnblogs.com/Lhxxx/p/11599919.html
Copyright © 2011-2022 走看看