Java中产生随机数
1 . 调用java.lang下面Math类中的random()方法产生随机数
public class MyRandom {
public static void main(String[] args) {
int radom = (int)(Ma...
分类:
编程语言 时间:
2015-06-19 10:40:59
阅读次数:
293
题意还是需要看原题,不好描述。实际上这个题只需要注意一点,就是把关系式改成递推式,然后就可以发现第二项完全决定了后面的位置,所以二分第二项的高度即可。import java.util.*;import java.io.*;import java.math.*;public class Main { ...
分类:
其他好文 时间:
2015-06-18 21:35:52
阅读次数:
103
在js中计算5/2,不会像在java中得到2,结果会是2.5,那如何得到整数2呢,整合下搜索结果,总共有以下几种方法:parseInt(5/2)Math.floor(5/2)5/2|0第三种特别说明下,‘|‘是位运算符,js中位运算之前会转为整数,与0位运算结果还是本身,所以也能达到取整数的目的。
分类:
Web程序 时间:
2015-06-18 11:45:24
阅读次数:
245
13 Roman to Integer链接:https://leetcode.com/problems/roman-to-integer/
问题描述:
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Hide Tags Math St...
分类:
其他好文 时间:
2015-06-18 09:47:10
阅读次数:
167
12 Integer to Roman链接:https://leetcode.com/problems/integer-to-roman/
问题描述:
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.Hide Tags Math St...
分类:
其他好文 时间:
2015-06-18 09:45:27
阅读次数:
170
apply,call应该是我们比较熟悉的方法,像Math.max.apply(arr),取数组元素中的最大值,Array.prototype.slice.call(obj)把obj变为数组等方法已经说明了apply及call的使用,
这两者在性能上并无区别,只不过在后面参数上有一定差异,apply的参数是数组形式,而call则是单个元素的形式,譬如我们在网上看到的最常见的add.call(sub...
分类:
移动开发 时间:
2015-06-18 09:44:02
阅读次数:
170
StringBuilder sb = new StringBuilder(1024); //向sb中写入900个左右的随机字符内容for(int j=1; j< 50;j++){ sb.append(Math.random());} //System.out.println(...
分类:
其他好文 时间:
2015-06-18 07:03:28
阅读次数:
137
函数导入的三种方式frommathimportsqrt#importthesqrtfunctiononly
e.g.sqrt(25)
frommathimport*#importallfunctionsfrommathmodule
e.g.sqrt(25)
importmath#importmathmodule,andusethefunctionviamath.*e.g.math.sqrt(25)type函数的比较defdistance_from_zero(a):
if(type(..
分类:
编程语言 时间:
2015-06-18 01:58:16
阅读次数:
150
文件score.dat中保存的是若干名学生的姓名和C++课、高数和英语成绩。
(1)定义学生类,其中包含姓名、C++课、高数和英语成绩及总分数据成员。
//定义学生类
class Student{
public:
//声明必要的成员函数
private:
string name;
double cpp;
double math;
double engli...
分类:
其他好文 时间:
2015-06-17 21:32:45
阅读次数:
102
1.不能显式地创建一个Math对象,直接使用它就可以了;2.Math对象不能存储数据,和String,Date对象不同;3.前面知道了parseInt()函数会通过消去小数点后面的一切,来使一个小数变成整数(因此24.999变为24).经常我们需要更精确的计算。于是通过Math对象的这几个方法:ro...
分类:
编程语言 时间:
2015-06-17 21:17:11
阅读次数:
119