java测试小代码总结

// 测试new Date()毫秒值
	public static void main(String[] args) {
		Long id = 0L;
		String Id = "";
		for (int i = 0; i < 10000; i++) {
			Date date = new Date();
			String compare = String.valueOf(date.getTime());
			if(i==0){
				Id = compare;
				continue ;
			}
//			System.out.println("ID:" + Id);
			if(compare.equals(Id)){
				System.out.println("i值为:"+i+";compare:" + Id);
				System.out.println("值相同");
//				break ; 
			}
			Id = compare;
		}
	}

测试毫秒值在一段代码中的重复率

测试BigDecimal的divideAndRemainder()方法

public static void main(String[] args) {
	BigDecimal  bg1 = new BigDecimal("98.2");
	BigDecimal  bg2 = new BigDecimal("3");
	BigDecimal[] divideAndRemainder = bg1.divideAndRemainder(bg2);
	for (BigDecimal bigDecimal : divideAndRemainder) {
		System.out.println(bigDecimal);
	}
}

结果:
32.0
2.2

猜你喜欢

转载自blog.csdn.net/qq_37375667/article/details/100058667
今日推荐