BigDecimal适用于财务类软件,是高精度类。
BigDecimal类的对象进行数学计算时要调用方法。
DecimaFormatl类是什么?
DecimalFormat是数据格式类。
#指任意数字
,指千分位
.表示小数
0表示不够的用0补足
DecimalFormat df = new DecimalFormat("###,###.##");
String str = df.format(12345.6); // 要用字符串变量来接收这个format后的值
打印输出str为:12,345.6
//生成0-4的随机数值
Random r = new Random();
int i = r.nextInt(5);
发现一个有趣的for循环写法,int j:arr 表示 j从arr数组中取值。用以输出不重复random数值。
public static boolean contains(int[] arr,int key){
for (int j : arr) {
if (j == key) return true;
}
return false;
}