特定几率下字符的输出以及数值格式的转换
来源:互联网 发布:保罗西蒙加芬克尔知乎 编辑:程序博客网 时间:2024/05/17 03:34
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Calendar;
import java.util.Random;
public class H {
public static void main(String[] args) {
int w=1000000000;
long e=1000000000000000000l;
String a="100";
int b= Integer.valueOf(a);
// 输出特定几率下的字母的例子(wrong)
String tmp = new String();
int chance = Calendar.MILLISECOND;
if (chance < 10) {
tmp = "A";
}
else if (chance < 20)
{
tmp = "B";
}
else if (chance < 55)
{
tmp = "C";
}
else if (chance < 80)
{
tmp = "D";
}
else
{
tmp = "E";
}
// 输出特定几率下的字母的例子(right)
char chRet = '/0';
Random rand = new Random();
int randNum = rand.nextInt(100);
if (randNum < 10) {
chRet = 'A';
}
else if (randNum < 10 + 10)
{
chRet = 'B';
}
else if (randNum < 10 + 10 + 35)
{
chRet = 'C';
}
else if (randNum < 10 + 10 + 35 + 25)
{
chRet = 'D';
}
else
{
chRet = 'E';
}
String ww = convCommaInt(w);
String ee = convCommaNum(e);
System.out.println(ww);
System.out.println(ee);
System.out.println(b);
System.out.println(tmp);
System.out.println(randNum);
System.out.println(chRet);
}
// 数值格式转换
public static String convCommaInt(int i) {
NumberFormat nf = new DecimalFormat("#,###,###,###");
String s = "";
s = nf.format(i);
return s;
}
// 数值格式转换
public static String convCommaNum(double d) {
NumberFormat nf = new DecimalFormat("###,###,###,###,##0.###############");
String s = "";
s = nf.format(d);
return s;
}
}
- 特定几率下字符的输出以及数值格式的转换
- 字符 和 数值的转换
- 在输出数值的格式表示符
- cout如何输出数值的二进制格式
- format 自定义数值格式的字符
- 字符串转换成特定的时间格式
- 数值型和字符型转换,以及string--char*--CString之间的转换
- ABAP中将字符格式的金额转换为数值的函数
- ABAP中将字符格式的金额转换为数值的函数
- ABAP中将字符格式的金额转换为数值的函数
- python的字符输出格式
- 数值转换为金额格式的函数
- 作业03: 数值的输出转换
- 字符和数值的相互转换
- 数值、字符之间的相互转换
- SQL将日期按特定的英文格式输出
- C语言找出字符串中的特定的字符,并输出
- 字符串之间相互转换 字符与数值之间的转换
- 如果Google面试让你用python写一个树的遍历程序
- Asp.net(C#)操作Excel的问题
- Error: PLS-00103: 出现符号 "CREATE"在需要下列之一时:
- repo 的一些用法和理解
- 林语堂
- 特定几率下字符的输出以及数值格式的转换
- 删除array数组中的重复项的实现代码
- The Video4Linux2 API: an introduction
- 2011 4-12 boost source code reading -
- oracle 数值类型都转换为number类型存储
- mysql中用source命令导入sql文件
- 解析:Program received signal: “EXC_BAD_ACCESS"(
- 汉字转拼音
- win7中常用设置