java basis of Chapter 11. Date, Math, automatic boxing and unboxing

Date class represents a moment is a moment
*
* Constructors:
* public Date (); // Create a Date object of the current system time
* public Date (long time); // milliseconds, from standard time (1970.1. 10:00 point 0 seconds) of milliseconds
*
* member methods:
* Long the getTime (); // get the current target date (date object) from the standard time of milliseconds
*
* milliseconds ---> date Object: public DATE (Long Time)
* DATE objects ----> milliseconds: Long the getTime ();
*
* second category: DateFormat is an abstract class, but we chose to use its subclasses provide java: the SimpleDateFormat
*
* constructor:
* public SimpleDateFormat (String pattern); // create a date formatting objects in the specified mode
* For example: a date object you want to print out the final format: "at 10:20:15 on June 5, 2017"
*
* Membership method:
* public string the format (Date D); // the specified Date object into a string back to you
* public Date parse (string time) ; // parse the given string into a string Date object

static void demo03 public () throws ParseException {
// a Date object you want to print out the final format: "at 10:20:15 on June 5, 2017"
SimpleDateFormat SDF = new new SimpleDateFormat ( "yyyy-MM-dd HH: mm : SS ");
// call the format method sdf
a Date new new D = a Date ();
String Dstr = sdf.format (D);
System.out.println (Dstr);

String S =" 2010-06-13 10: 03:10 ";
a Date SD = sdf.parse (S);
System.out.println (SD);

public static void demo02 () {
// look at today's time zone standard time how many milliseconds
Date d = new Date () ;
Long d.getTime L = ();
System.out.println (L); // 1,497,401,350,108
}

Date: Date class, year, month, day, hour
* Calendar: Calendar class, year, month, day, hour
* We find Calendar is an abstract class, you can not use
* and we do not have a subclass
*
* Obtaining Calendar class object:
* public static Calendar getInstance (); // return a Calendar object is a subclass of
* [Time = 1497403287679, areFieldsSet = to true, to true areAllFieldsSet =,
* = the lenient to true, Zone = sun.util.calendar.ZoneInfo [ID = "Asia / of Shanghai ",
* offset = 28.8 million, dstSavings = 0, useDaylight = to false, transitions =. 19,
* lastRule = null], firstDayOfWeek =. 1, minimalDaysInFirstWeek =. 1, the ERA =. 1,
* YEAR = 2017, MONTH =. 5, WEEK_OF_YEAR = 24, the WEEK_OF_MONTH =. 3, DAY_OF_MONTH is = 14,
* DAY_OF_YEAR = 165, DAY_OF_WEEK =. 4, DAY_OF_WEEK_IN_MONTH = 2, for AM_PM = 0, HOUR =. 9,
* the HOUR_OF_DAY =. 9, MINUTE = 21 is, SECOND, = 27, for MILLISECOND = 679, ZONE_OFFSET = 28.8 million,
* DST_OFFSET = 0]

*
* Member method:
* 1.int GET (Field, int); // Gets the specified fields (member variables) value
* 2.void set (int field, int value); // the calendar object into the specified field the specified value
* 3.void add (int field, int amount); // the specified field in the calendar object increased specified value
* 4.public date getTime (); // the object into a current calendar date object
*


* system class: class system, the java.lang
*
* Check system API said that this class can not create object
*
* methods:
* public static void exit (int code); // exit JVM, the latter parameter write 0 indicates normal termination
* public static void gc (); // notify JVM's garbage collector over rag
* public static String getProperty (String key ); // Get a property of a system
* public static long currentTimeMillis (); // get the current time value in milliseconds
*
*


* the math class: class related to the mathematical operation
*
* static Double 1.public ABS (Double D); // absolute value
* 2.public staic double max (double d1 , double d2); // whichever is greater
* 3.public staic double min (double d1 , double d2); / takes a small value
*
* static Double 4.public Random ( ); // returns a random number range [0.0,1.0)
*
* static 5.public Long round (Double D); // rounding, decimal place is determined only
* 6.public static double pow (double d1 , double d2 ); // d1, d2 required power
*
* static Double 7.public Floor (Double D); // rounded down
* 8.public static double ceil (double d ); // ceil


* ArrayList set only can store reference type
* java the basic type 8 corresponding to the basic data types packaging
* byte Short char int Long a float Double Boolean
* byte Short Character integer Long the Float Double Boolean
* set ArrayList define a stored integer <integer> nums = new. ...
* a further effect: to turn into a string of basic types of functions corresponding to
* Public String [] split (String regex) expression matching Splits this string given positive. * * Example 1:




























* Check qq number.
*
*

Public class RegexDemo01 {

static void main public (String [] args) {
// the TODO Auto-Generated Method Stub
splitDemo02 ();
}
/ *
* a regular expression parsing the string
* /
public static void splitDemo02 () {
String IP = "192. ..168 ..... 1 ..... 1 ";
// write code to come up with every digital
// regular expression" "stands for any character.
// translated characters: \ the n-\ t
//" . \ ": the" "special meaning removed
String [] ips = ip.split (" . \\ + "); // in two regular expression" \\ "represents a" \ "
the System.out. the println (ips.length);
for (int I = 0; I <ips.length; I ++) {
System.out.println (IPS [I]);
}
}
/ *
* a regular expression parsing the string
* /
static void splitDemo public () {
String S = "0218--3422 --- ----- 3540 4565";
// write code to each cornet out output
// regular expression "+" indicates a plurality of front elements
String [] = s.split the nums ( "- +");
for (int I = 0; I <nums.length; I ++) {
the System.out. the println (the nums [I]);
}



}

/ *
* matching phone number
* 1: 11-digit number is required
* 2: 1 to 1 bit, 2 bits in a 3,4,5,7,8,
* 9 back to any number between 0 and 9.
*
* /
Public static void Phone () {
String NUM = "12,838,385,438";
Boolean num.matches B = ( ". 1 [34578] [0-9] {}. 9"); //
System.out.println (B) ;
}
/ *
* a regular expression test QQ number
* QQ number rule:
* 1 must both digital
* 2 digits must be 5-12 bits
* 3. the first digit can not be 0
* /
public static void QQ ( ) {
// definition of a QQ number
String qq = "283834567765438";
// regular expression in brackets indicates the scope of our
// number of regular expressions in braces
boolean b = qq.matches ( "[1-9 ] [0-9] {4,11}");
System.out.println (B);

}

}

 

* Ability to understand the regular expression to validate 11 phone numbers
* Ability to understand the regular expression to validate QQ number
*
* be able to use the date class A output current date
* constructed:
* public a Date ();
* public a Date (Long Time);
* member methods :
* public Long the getTime ();
* be able to tell the date formatted string method
* DateFormat -----> the SimpleDateFormat
* configuration:
* public the SimpleDateFormat (string pattern); // pattern mode, must be given in accordance with APi the lETTERS
* method:
* a Date Object ---> String format: public String the format (a Date D)
* String format ---> Date Object: a Date public the parse (String S);
*
* Calendar category:
* Get sub Calendar Object class:
* the getInstance public static Calendar (); // return a Calendar actual subclass (type calendar) Object
* method:
* public void the Add (Field int, int value);
Public void SET * (Field int, int value);
* GET public int (int Field);
* a Date public the getTime (); // Return value corresponding to the target date calendar object

public class Test1 {
public static void main (String [] args) throws Exception {
// int System.in.read = Read ();
// System.out.println (Read);

Scanner Scanner dd new new = (the System.in);
System.out.println ( "Please enter your Year want to query: ");
int year = dd.nextInt ();
Calendar c = Calendar.getInstance ();
// c.set (year, 2,0);
c.set (year, 2,1);
c.add (Calendar.DATE, -1);
System.out.println ( "February this year" + c.get (Calendar.DATE) + "days");
}
}


/ *
* Any keyboard input specified date format (yyyy-MM-dd), showing the corresponding day of the week
*
* "E" represents the week
* /
System.out.println ( "Enter a specified format:" );
string = S new new Scanner (the System.in) .nextLine ();
// define the date format objects, for converting the character string input by the user to date object
DateFormat df = new SimpleDateFormat ( "yyyy -MM-dd" );
// convert a string to date target
a date df.parse D = (S);
// define the date format objects, for converting date object specified string object
SimpleDateFormat sdf = new SimpleDateFormat ( " E ");
// parse the date string object
string = sdf.format STR (D);
System.out.println (STR);

. investigation subject string parsing calculates an average value of all reference numbers and strings type conversion
information has been given:
String = S "a first set of scores: 92.8, a second set of scores: 88.8, the third set of scores: 95.4";

String S = "a first set of scores: 92.8, a second set of scores: 88.8, the third group score: 95.4 ";
. @ 1 other than the regular expression defined, matching digits and comma characters, using replaceAll method, all the numeric string other than
the replacement character out //
String s1 = "the [one hundred twenty-three] set of scores:";
s.replaceAll S2 = String (S1, "");
String [] = S3 s2.split ( ",");
double SUM = 0;
// iteration number, and the numbers are converted to Demi a double type element after the summation
for (String String: S3) {
// the Integer.parseInt = SUM + (String);
SUM Double.parseDouble + = (String);
//System.out.println(string);
}
// averaging number of
Double SUM = I / (s3.length);
System.out.println (I);


* corresponding to the basic data types write eight packaging
* int ---> Integer
* char ---> Character
* write string into the basic data type methods
* the Integer.parseInt ( "20 is");
* Double.parseDouble ( "99.95");
* Write converted into a string of basic data types embodiment
* the simplest: 4 + "" ===> "4"
* Be able to say unpacking boxes concept
* unboxing: packaging -> basic types
* Packing: basic types -> wrapper class
* Ability to master the use of common methods of class System
* public static long currentTimeMillis (); // get the current time of milliseconds
* // unimportant
* public void exit (0); // terminate the JVM
* public void gc (); // tells the system needs to run the system garbage collector
* public String getProperty (String key) ; // get some system-related attribute value
* math class can be used for performing mathematical operations
* Double 1.public Random (); //
* 2.public Long round (Double d); // rounding the parameter d
*
* Double 3.public ceil (double d) // ceil
* 4.public double floor (double d) // rounded down
*
* Double 5.public POW (Double d1, d2 Double); // find a multiplying d1, d2 product

Guess you like

Origin www.cnblogs.com/haizai/p/11071928.html