Javaツールクラス-日付取得、乱数、システムコマンド、データ型変換

14815 ワード

  1 package tems;

  2 

  3 import java.text.SimpleDateFormat;

  4 import java.util.Arrays;

  5 import java.util.Calendar;

  6 import java.util.Date;

  7 import java.util.List;

  8 import java.util.Random;

  9 import java.util.Scanner;

 10 

 11 /**

 12  * Math 

 13  * 

 14  * */

 15 class Demo6{

 16     public static void main(String[] args){

 17         //   

 18         Math.ceil(34.5);//            

 19         Math.floor(34.5);//            

 20         //      

 21         Math.pow(2,3);

 22         //    

 23         Math.round(12.54);

 24     }

 25 }

 26 /**

 27  * Date 

 28  * 

 29  * */

 30 class Demo2{

 31     public static void main(String[] args) throws Exception {

 32         //      

 33         Date date = new Date();

 34         //                

 35         SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd E HH:mm:ss");

 36         String sss = sdf.format(date);

 37         //      (date)

 38         String s="2015-03-08";

 39         SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-dd-MM");

 40         sdf.parse(s);

 41     }

 42 }

 43 /**

 44  * Calendar 

 45  * 

 46  * */

 47 class Demo3{

 48     public static void main(String[] args){

 49         Calendar c=Calendar.getInstance();

 50         //      

 51         c.get(Calendar.YEAR);// 

 52         c.get(Calendar.MONTH+1);// 

 53         c.get(Calendar.DAY_OF_MONTH);// 

 54         c.get(Calendar.DAY_OF_WEEK);//  

 55         //    

 56         //set(int year,int month,int date)

 57         c.set(2012,2,18);

 58         //            

 59         c.add(Calendar.DAY_OF_MONTH, -18);

 60     }

 61 }

 62 /**

 63  * Random 

 64  * 

 65  * */

 66 class Demo4{

 67     public static void main(String[] args){

 68         Random r = new Random();

 69         int random = r.nextInt(10)+1;

 70     }

 71 }

 72 /**

 73  * Scanner 

 74  * 

 75  * */

 76 class Demo5{

 77     public static void main(String[] args){

 78         //       

 79         Scanner scanner = new Scanner(System.in);

 80         int guess = scanner.nextInt();

 81         // OJ   ,              

 82         //while(sc.hasnext()){}

 83     

 84     }

 85 }

 86 /**

 87  * Runtime 

 88  * 

 89  */

 90 

 91 class Demo {

 92     /*  Runtime     getRuntime()  

 93      * Runtime          。

 94      *  :Runtime    java        。         */

 95     public static void main(String[] args) throws Exception {

 96         Runtime run=Runtime.getRuntime();//        

 97         Process p=run.exec("c:\\winmine.exe");//    

 98         p.destroy();//    

 99         Process p1=run.exec("notepad.exe demo.txt");

100         p1.destroy();

101         

102     }

103     

104 }

105 /**

106  *          

107  * 

108  * */

109 class Demo7{

110     public static void main(String[] args){

111 //    

112         //

113         String s1 = Integer.toHexString(60);

114         //

115         Integer.parseInt("3c",16);    

116 //  <—>  

117         List <String>al=Arrays.asList(s1);

118         String s[]=al.toArray(new String[10]);

119     }

120 }