首页 > 其他 > 详细

动手动脑10.14

时间:2018-10-14 15:14:14      阅读:106      评论:0      收藏:0      [点我收藏+]

一、

技术分享图片

 

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("\nThe 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()方法中实参表内可输入很多类型。

动手动脑10.14

原文:https://www.cnblogs.com/quyangzhangsiyuan/p/9786208.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!