随机数 Stringbuffer
Random
package com.xiaohu.dao;
import java.util.Random;
public class DAO1 {
public static void main(String[] args) {
StringBuffer sa = new StringBuffer();
Boolean flag = false;
sa.append("hello");
sa.append("world!");
sa.append(flag);
System.out.println(sa);
Random rad = new Random();
int num = rad.nextInt(50);
Boolean b = rad.nextBoolean();
System.out.println(num);
System.out.println(b);
Random rad1 = new Random(20);
int r1 = rad1.nextInt();
System.out.println(r1);
}
}
综合案例
Canlendar
Calendar canlandar = Calendar.getInstance();
package com.xiaohu.dao;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class DAO3 {
public static void main(String[] args) {
String oldName = "tt.jpg";
String lastName = oldName.substring(oldName.lastIndexOf('.'));
System.out.println(lastName);
Date d = new Date();
SimpleDateFormat f = new SimpleDateFormat("yyyyMMddhhmmss");
String time = f.format(d);
Random rad = new Random();
int num = rad.nextInt(Integer.MAX_VALUE);
StringBuffer s = new StringBuffer();
s.append(time);
s.append(num);
s.append(lastName);
System.out.println(s);
}
}
数学函数
package com.xiaohu.dao;
public class DAO4 {
public static void main(String[] args) {
double x1 = Math.abs(-23);//绝对值
double x2 = Math.ceil(13.267);//向上取整
double x3 = Math.floor(13.267);//向下取整
double x4 = Math.max(11,22);//两数最大值
double x5 = Math.round(11.5);
double x6 = Math.round(11.2);//四舍五入
double x7 = Math.random();//随机数
double x8 = Math.sqrt(16);//开方
System.out.println(x8);
}
}