Java Tool Classes-date acquisition, random number, System command, data type conversion

Source: Internet
Author: User

1  Packagetems;2 3 ImportJava.text.SimpleDateFormat;4 Importjava.util.Arrays;5 ImportJava.util.Calendar;6 Importjava.util.Date;7 Importjava.util.List;8 ImportJava.util.Random;9 ImportJava.util.Scanner;Ten  One /** A * Math class -  *  -  * */ the classdemo6{ -      Public Static voidMain (string[] args) { -         //take an integer -Math.ceil (34.5);//returns the smallest integer greater than this number +Math.floor (34.5);//returns the largest integer less than this number -         //Square or root +Math.pow (2,3); A         //Rounding atMath.Round (12.54); -     } - } - /** - * Date Class -  *  in  * */ - classdemo2{ to      Public Static voidMain (string[] args)throwsException { +         //Get current Time -Date Date =NewDate (); the         //perform the format of the date display in your own way *SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy/mm/dd E HH:mm:ss"); $String SSS =Sdf.format (date);Panax Notoginseng         //string-to-date (date) -String s= "2015-03-08"; theSimpleDateFormat sdf2=NewSimpleDateFormat ("yyyy-dd-mm"); + Sdf.parse (s); A     } the } + /** - * Calendar class $  *  $  * */ - classdemo3{ -      Public Static voidMain (string[] args) { theCalendar c=calendar.getinstance (); -         //get year Month dayWuyiC.get (calendar.year);//years theC.get (calendar.month+1);//Month -C.get (Calendar.day_of_month);//Day WuC.get (Calendar.day_of_week);//Week -         //Set Date About         //set (int year,int month,int date) $C.set (2012,2,18); -         //Add and delete the current date -C.add (Calendar.day_of_month, 18); -     } A } + /** the * Random class -  *  $  * */ the classdemo4{ the      Public Static voidMain (string[] args) { theRandom r =NewRandom (); the         intRandom = R.nextint (10) +1; -     } in } the /** the * Scanner class About  *  the  * */ the classdemo5{ the      Public Static voidMain (string[] args) { +         //entering data from the keyboard -Scanner Scanner =NewScanner (system.in); the         intGuess =scanner.nextint ();Bayi         //in the case of OJ, the input method used in the face of uncertain data the         //While (Sc.hasnext ()) {} the      -     } - } the /** the * Runtime class the  *  the  */ -  the classDemo { the     /*The GetRuntime () method is required to get the runtime object the * The runtime class is a simple interest design pattern. 94 * Note: runtime can only kill Java Virtual machine-initiated processes. Do not kill the system process*/ the      Public Static voidMain (string[] args)throwsException { theRuntime Run=runtime.getruntime ();//get the current running object theProcess p=run.exec ("C:\\winmine.exe");//Open Process98P.destroy ();//Close Process AboutProcess p1=run.exec ("notepad.exe demo.txt"); - P1.destroy ();101         102     }103     104 } the /**106 * Conversion between data types107  * 108  * */109 classdemo7{ the      Public Static voidMain (string[] args) {111 //Binary Conversion the         //decimal to other binary:113String S1 = integer.tohexstring (60); the         //other binary into decimal: theInteger.parseint ("3c", 16);  the //Arrays <-> Collections117List <string>al=arrays.aslist (S1);118String S[]=al.toarray (NewString[10]);119     } -}

Java Tool Classes-date acquisition, random number, System command, data type conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.