码迷,mamicode.com
首页 > 其他好文 > 详细

动手动脑10.14

时间:2018-10-14 16:31:19      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:The   使用   rgs   很多   img   for   double   sys   相同   

一、

技术分享图片

 

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

标签:The   使用   rgs   很多   img   for   double   sys   相同   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!