zoukankan      html  css  js  c++  java
  • Java常用类

    1、随机输出班上5名学生的学号。

    import java.util.*;
    public class num3 {
    
    	public static void main(String[] args){
    		int a[];
    		a = new int[5];
    		
    		for(int i=0;i<5;i++){
    			a[i]=(int)(Math.random()*55+1);
    			System.out.println(a[i]);
    		}
    	}
    }
    

    2、获取当前系统时间,运用subString()方法,显示年份。
    3,使用Calendar类显示当前日期。

    
    import java.text.SimpleDateFormat;
    import java.util.*;
    public class fate {	
    	public static void main(String[] args) {
    		Date date = new Date();
    		System.out.println("时间:"+date);
    		String strDate = date.toString();
    	    String year = strDate.substring(24,28);
    	    String month = strDate.substring(4,7);
    	    String day = strDate.substring(9,10);
    	    String hour = strDate.substring(11,13);
    	    String min = strDate.substring(14,16);
    	    String sec = strDate.substring(17,19);	    
    	    System.out.print(year+"年");
    	    System.out.print(month+"月");
    	    System.out.print(day+"日   ");
    	    System.out.print(hour+"时");
    	    System.out.print(min+"分");
    	    System.out.println(sec+"秒");
    	  //2,获取当前系统时间,运用subString()方法,显示年份。
    	    SimpleDateFormat dateformat1=new SimpleDateFormat("yyyy年");
    	    String a1 = dateformat1.format(new Date());
    	    System.out.println("时间:"+a1);
    	  //3,使用Calendar类显示当前日期。
    	    Calendar a2 = Calendar.getInstance();      
    	    System.out.print(a2.get(Calendar.YEAR)+"年");
    	    System.out.print((a2.get(Calendar.MARCH)+1)+"月");
    	    System.out.print(a2.get(Calendar.DATE)+"日");
    	    System.out.print(a2.get(Calendar.HOUR)+":");
    	    System.out.print(a2.get(Calendar.MINUTE)+":");
    	    System.out.print(a2.get(Calendar.SECOND));	    
    	}
    }
    

    4、分别利用ArrayList类、LinkedList类、Vector类创建集合,并实现相关用法。

    import java.util.*;
    public class fate {	
    	public static void main(String[] args) {
    		ArrayList a1 = new ArrayList();
    		a1.add("月");
    		a1.add("火");
    		a1.add("水");
    		a1.add("木");
    		a1.add("金");
    		a1.add("土");
    		a1.add("日");
    		int i;
    		Scanner c = new Scanner(System.in);		
    		System.out.println("输入星期数");
    		i = c.nextInt();
    		System.out.println(a1.get(i-1)+"曜日");
        }
    }
    

    5、总结

          没有及时的做好课前预习和课后复习工作,导致上实训课的时候比较吃力,原来上课听懂的地方也会变得模糊,需要翻书。
    

    实验内容和原理:

    1、 将布尔型、整型、长整型、双精度型作为参数,实例化相应的包装类对象,并输出对象的数值。

    2、 按照“XXXX年XX月XX日 XX时XX分XX秒”的格式,输出当前时间。
    以下来自https://www.cnblogs.com/sucker/p/10980183.html

    package work;
    
    public class Work1 {
        Boolean b;
        Integer i;
        Long l;
        Double d;
        public Work1(boolean b, int i, long l, double d)
        {
            this.b = new Boolean(b);
            this.i = new Integer(i);
            this.l = new Long(l);
            this.d = new Double(d);
            System.out.println(this.b);
            System.out.println(this.i);
            System.out.println(this.l);
            System.out.println(this.d);
        }
        public static void main(String[] args) {
            new Work1(true, 99, 1437631334, 5.4451356);
        }
    }
    
    package work;
    
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
    
    public class work2 {
        public static void main(String[] args) {
            Date d = new Date();
            DateFormat df = new SimpleDateFormat("yyyy年MM月dd日    HH时mm分ss秒", Locale.CHINA);
            System.out.println(df.format(d));        
    
        }
    
    }
    
  • 相关阅读:
    Linux内核空间-用户空间通信之debugfs
    Mysql 启动失败 报错 1067
    [置顶] hdu3018解题报告--也是白话几笔画学习总结
    【Todo】蒙特卡洛(蒙特卡罗)树 & 卷积网络
    基本分类方法——KNN(K近邻)算法
    SVM(支持向量机)与统计机器学习 & 也说一下KNN算法
    可重入锁 & 自旋锁 & Java里的AtomicReference和CAS操作 & Linux mutex不可重入
    【Todo】Nginx架构学习
    【转载】C++异常机制的学习
    关于协程的学习 & 线程栈默认10M
  • 原文地址:https://www.cnblogs.com/BKKITO/p/10978808.html
Copyright © 2011-2022 走看看