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

    一、

    public class Suiji{
    public long a=12345L;
    public long c=12345L;
    public long m=456123L;
    public long r=1;
    public long rand() {
    r=(r*a+c)%m;
    return r;
    }
    public static void main(String[] args) {
    Suiji s=new Suiji();
    long r;
    for(int i=1;i<1000;i++) {
    r=s.rand();
    System.out.println(r);
    }
    }
    }

     

    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)//int类型
    {
    return x * x;
    }

    public static double square(double y)//double类型
    {
    return y * y;
    }
    }

    输出结果

    The square of integer 7 is  49

    The square of double 7.5 is 56.25

    该程序中所使用两个函数虽然名字相同,但由于实参类型不同且返回值类型不同,并不会发生冲突。

    上述示例代码展示了Java的“方法重载(overload)”特性。

    满足以下条件的两个或多个方法构成“重载”关系:

    (1)方法名相同;

    (2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。

    System.out.println()方法中实参表内可输入很多类型。

  • 相关阅读:
    ios7 苹果原生二维码扫描(和微信类似)
    ios7之后 根据UILabel的文字计算frame的方法
    [Luogu1944] 最长括号匹配
    [bzoj3916] friends
    [NOIp2006] 能量项链
    [NOIp2003] 加分二叉树
    [Luogu1353] 跑步Running
    [Luogu2214] Mooo Moo S
    [POJ2452] Sticks Problem
    [POJ2406] Power Strings
  • 原文地址:https://www.cnblogs.com/quyangzhangsiyuan/p/9786208.html
Copyright © 2011-2022 走看看