public class MainClass{
public static void main(String[] args) throws Exception {
Random random = new Random();
for (int i = 0; i < 10; i ++) {
System.out.print(random.nextInt(100) + "、");
}
}
}
public class MainClass{
public static void main(String[] args) throws Exception {
Random random = new Random();
int[] date = new int[7]; // 开辟一个7个元素的数组
int foot = 0; // 此为数组操作交表
while (foot < 7) { // 不知道多少次循环可以保存完数据,所以使用while循环
int t = random.nextInt(37); // 生成一个不大于37的随机数
if (!isRepeat(date, t)) { // 重复
date[foot ++] = t; // 保存数据
}
}
Arrays.sort(date);
for (int i = 0; i < date.length; i ++) {
System.out.print(date[i] + ", ");
}
}
/**
* 此方法主要是判断是否存在有重复的内容,但是不允许保存0
* @param temp 指的是已经保存的数据
* @param num 新生成的数据
* @return 如果成功的保存了,那么返回true,否者返回false
*/
public static boolean isRepeat(int[] temp, int num) {
if (num == 0) { // 没有必要向下继续判断
return true;
}
for (int i = 0; i < temp.length; i ++) {
if (temp[i] == num) {
return true;
}
}
return false;
}
}
public class MainClass{
public static void main(String[] args) throws Exception {
System.out.println(Double.MAX_VALUE * Double.MAX_VALUE); // Infinity
}
}
public class MainClass{
public static void main(String[] args) throws Exception {
BigInteger biga = new BigInteger("894165498148168684618");
BigInteger bigb = new BigInteger("48154687351354698415");
System.out.println("加法操作:" + biga.add(bigb));
System.out.println("减法操作:" + biga.subtract(bigb));
System.out.println("乘法操作:" + biga.multiply(bigb));
System.out.println("除法操作:" + biga.divide(bigb));
// 数组里面只有两个元素:第一个元素表示的是商,第二个元素表示的是余数
BigInteger[] result = biga.divideAndRemainder(bigb);
System.out.println("商:" + result[0] + ",余数:" + result[1]);
}
}
class MyMath {
/**
* 实现准确位数的四舍五入操作
* @param num 要进行四舍五入的数字
* @param scale 要保留的小数位
* @return 处理后的四舍五入数据
*/
public static double round(double num, int scale) {
BigDecimal biga = new BigDecimal(num);
BigDecimal bigb = new BigDecimal(1);
return biga.divide(bigb, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
}
public class MainClass{
public static void main(String[] args) throws Exception {
System.out.println(MyMath.round(19.79469494, 2));
System.out.println(MyMath.round(-15.5, 0));
System.out.println(MyMath.round(15.5, 0));
}
}