大家好,今天小编关注到一个比较有意思的话题,就是关于java语言public class的问题,于是小编就整理了3个相关介绍Java语言public class的解答,让我们一起看看吧。
请问JAVA中获取系统当前时间该怎么写?
import j***a.util.Date;
import j***a.text.SimpleDateFormat;
public class Nowstring {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
}
}
publicstaticvoidmain(stringargs[]){
//new一个date对象
dated=newdate();
longt=d.gettime();//获取当前的毫秒数
t+=(6*24*60*60*1000);//当前毫秒数加上一天的毫秒数(1*24*60*60*1000)
d.settime(t);//将总毫秒数重新赋值给date对象
system.out.println(d);//现在的d就是当前时间加上一天后的时间对象
//以下是将时间格式化输出的日期
stringsd=newsimpledateformat("yyyy-mm-ddhh:mm:ss").format(d);
system.out.println(sd);
J***a定义一个Student类,包括学号、姓名、性别、班级、出生日期?
public class Student { private int no; private String name; private String gender; private String studentCalss; private Date birthday;}class Date{ private int year; private int month; private int day;}
j***a随机字符串生成?
代码如下,供参考:
import j***a.util.random;public class Main { public static void main(String[] args) { char[] chs = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; String str = new Main().getStr(chs); System.out.println(str); } public String getStr(char[] chs) { String str = ""; Random random = new Random(); for (int i = 0; i < 4; i++) { // 这种写法易于扩展,chs内容改了不用修改代码 str += chs[random.nextInt(chs.length)]; } str += random.nextInt(10); str; }}
到此,以上就是小编对于j***a语言public class的问题就介绍到这了,希望介绍关于j***a语言public class的3点解答对大家有用。