2016 10月15日java的动手动脑
(1) 编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数。
源程序:
//随机数的产生
//zhanxinwu,October,15,2016
public class Recur
{
private static final int N = 10;
private static final int LEFT = 40;
private static final int RIGHT = 100;
private static long x0 = 1L;
private long a = 1103515245L;
private long c = 12345L;
private long m = 2147483648L;
// 产生随机数
private long rand ( long r )
{
// a,c,m为常数
r = ( r * a + c ) % m;
return r;
}
* @param a
* @param b
* @param rand
* @return
*/
private long little ( int a, int b, long rand )
{
return a + rand % ( b - a + 1 );
}
private void recursion ( int count, long rand )
{
if (count >= N)
{
return;
}
rand = rand (rand);
long r = little (LEFT, RIGHT, rand);
System.out.print (r + " ");
recursion (++count, rand);
}
public static void main ( String[] args )
{
Recur recur = new Recur ();
recur.recursion (0, x0);
}
}
改程序就调用了Xn+1 =(aXn+c)mod m;的公式进行编辑
public class MethodOver load {
public static void main (String[] args){
System.out.println(“The sqare of integer 7 is” +square(7));
System.out.println(“The sqare of double 7.5 is” +square(7));
}
Public static int square(int x){
Return x*x;
}
Public static double square(double y){
Return y*y;
}
}
答:该程序上述示例代码展示了Java的“方法重载(overload)”特性。
满足以下条件的两个或多个方法构成“重载”关系:
(1)方法名相同;
(2)参数类型不同,参数个数不同,或者是参数类型的顺序不同。
注意:方法的返回值不作为方法重载的判断条件
答:改程序主要是输入一个数如何识别,调用哪个函数的类型,最终改程序可以判断的是输入值的类型,来确定调用函数是哪一个。
2016 10月15日java的动手动脑的更多相关文章
- 2016年10月15日 星期六 --出埃及记 Exodus 18:26
2016年10月15日 星期六 --出埃及记 Exodus 18:26 They served as judges for the people at all times. The difficult ...
- 10月15日 | 云栖大会“淘宝移动技术实践&开放论坛”来了!
参会报名链接:http://baichuan.taobao.com/marketing/yunqi#?baichuan_channel=cnblogs 顺应移动互联网消费升级趋势, 淘宝作为移动领域的 ...
- 10月27日Java整理
实验一:凯撒密码 import java.util.Scanner; //zhanxinwu,October,25,2016 public class Addmi { public static vo ...
- 2015年10月15日学习html基础笔记
一个互联网公司的分工,小公司要求全能,拿一个项目全部做出来.大公司分工明细,主要步奏为策划人员策划方案,美工人员设计图有.psd.rp等,前端人员做静态页面,后台人员获取数据java php .net ...
- c# Equal函数 and 运算符'==' (原发布 csdn 2017年10月15日 20:39:26)
1.==.!=.<.>.<= 和>= 运算符为比较运算符(comparison operator).C#语言规范5.0中文版中比较运算符的描述如下: 2.通用类型系统 3.值类 ...
- 2016年12月15日 星期四 --出埃及记 Exodus 21:10
2016年12月15日 星期四 --出埃及记 Exodus 21:10 If he marries another woman, he must not deprive the first one o ...
- 2016年10月30日 星期日 --出埃及记 Exodus 19:15
2016年10月30日 星期日 --出埃及记 Exodus 19:15 Then he said to the people, "Prepare yourselves for the thi ...
- 2016年3月15日Android实习日记
1.解决了ScrollView滑动冲突问题. 2.设置好了“查看详解”与“题目编号”的部分. 3.完成了app启动图片的设置,并在启动的过程中开辟新的线程连接服务器并开启监听数据. 别忘了注册启动Ac ...
- 2016年11月15日 星期二 --出埃及记 Exodus 20:6
2016年11月15日 星期二 --出埃及记 Exodus 20:6 but showing love to a thousand of those who love me and keep my c ...
随机推荐
- Springboot集成swagger2生成接口文档
[转载请注明]: 原文出处:https://www.cnblogs.com/jstarseven/p/11509884.html 作者:jstarseven 码字挺辛苦的..... 一 ...
- C# 表达式树遍历(二)
一.前言 上一篇我们对表达式树有了初步的认识,这里我们将对表达式树进行遍历,只有弄清楚了他的运行原理,我们才可以对他进行定制化修改. 表达式系列目录 C# 表达式树讲解(一) C# 表达式树遍历(二) ...
- 排序入门练习题3 谁考了第k名 题解
题目出处:<信息学奥赛一本通>第二章 上机练习1 题目描述 在一次考试中,每个学生的成绩都不相同,现知道了每个学生的学号和成绩,求考第k名的学生的学号和成绩. 输入格式 输入的第一行包含两 ...
- apache ignite系列(八):问题汇总
1,java.lang.ClassNotFoundException Unknown pair 1.Please try to turn on isStoreKeepBinary in cache s ...
- Elastic Stack 笔记(七)Elasticsearch5.6 聚合分析
博客地址:http://www.moonxy.com 一.前言 Elasticsearch 是一个分布式的全文搜索引擎,索引和搜索是 Elasticsarch 的基本功能.同时,Elasticsear ...
- web-文件上传漏洞总结
思维导图: 一,js验证绕过 1.我们直接删除代码中onsubmit事件中关于文件上传时验证上传文件的相关代码即可. 或者可以不加载所有js,还可以将html源码copy一份到本地,然后对相应代码进行 ...
- React学习笔记(持续更新)
2.2页面加载过程 1.资源加载过程:URL->DNS查询->资源请求->浏览器解析 ①URL结构:http://www.hhh.com:80/getdata?pid=1#title ...
- mysql replace into使用
使用mysql插入数据时,我们通常使用的是insert into来处理,replace into有时可以替代insert into功能,但replace into也有自己的用法 准备一张测试表: CR ...
- layui 上传图片回显并点击放大实现
1.页面代码布局 <div class="layui-col-xs12 form-group"> <div class="layui-col-xs6&q ...
- springboot新版本(2.0.0+)自定义ErrorController中使用ErrorAttributes
2.0.0之前使用: @Autowired private ErrorAttributes errorAttributes; private Map<String, Object> get ...