. How to take the first two digits of the decimal point and rounding them out.
Package com. lovo; public class TestDot2 {// method 1 public void test1 (double c) {java. text. decimalFormat df = new java. text. decimalFormat ("#. # "); System. out. println (df. format (c);} // method 2 public void test2 (double c) {java. math. bigDecimal bd = new java. math. bigDecimal (String. valueOf (c); bd = bd. setScale (2, java. math. bigDecimal. ROUND_HALF_UP); System. out. println (bd);} // method 3 public void test3 (double c) {long l1 = Math. round (c * 100); // rounding double ret = l1/100.0; // Note: Use 100.0 instead of 100 System. out. println (ret);} public static void main (String [] args) {double c = 3.056; TestDot2 td2 = new TestDot2 (); td2.test1 (c ); // td2.test2 (c); // td2.test3 (c );}}
. Determine whether a date is the last day of the month and how to obtain the last day of the month.
Package com. lovo; import java. util. calendar; public class Test {public static void main (String [] args) {Calendar Ar c = Calendar ar. getInstance (); c. set (Calendar. YEAR, 2004); c. set (Calendar. MONTH, 11); c. set (Calendar. DAY_OF_MONTH, 30); System. out. println ("input date:" + c. get (Calendar. YEAR) + "-" + (c. get (Calendar. MONTH) + 1) + "-" + c. get (Calendar. DAY_OF_MONTH); judgeIsLastDay (c); getLastDay (c );}/*** Determine whether a date is the last day of the month ** @ param c */private static void judgeIsLastDay (Calendar c) {Calendar c1 = (Calendar) c. clone (); c. add (Calendar. DAY_OF_MONTH, 1); if (c. get (Calendar. MONTH )! = C1.get (Calendar. MONTH) {System. out. println ("the date you entered is the last day of the month");} else {System. out. println ("the date you entered is not the last day of the month ");}} /*** get the last day of the month of a date ** @ param c */private static void getLastDay (Calendar c) {c. add (Calendar. MONTH, 1); c. set (Calendar. DAY_OF_MONTH, 1); c. add (Calendar. DAY_OF_MONTH,-1); System. out. println ("the last day of the month is:" + c. get (Calendar. YEAR) + "-" + (c. get (Calendar. MONTH) + 1) + "-" + c. get (Calendar. DAY_OF_MONTH ));}}
33. How to arouse a method in the class? Step 3: 1. Generate a Class array to describe the parameters of the method (obtain the Class template array of the parameter to solve the problem of method overloading ). 2. Get the Method through the Class Object and Method parameters (get the Method to be awakened ). 3. Use method. invoke (instance, parameter value array) to wake up the method (wake up method ).