Packaging & Tool Classes

Source: Internet
Author: User

I. PACKING class

It is the form of encapsulating a basic data type into a class.

1. Common

(1) Long, (2) Integer, (3) Double, (4) Float, (5) Boolean: String In addition to true (case-insensitive), it goes to false.

2. Provide a type conversion method

(1) Example method (2) static method: Parselong ().

Two. Tool class

1.Math Math Tool Class

(1) rounding round;

(2) Upper value ceil (): the smallest integer greater than or equal to it;

(3) lower value floor (): The largest integer less than or equal to it;

(4) random number (): Random number between 0~1.

2.Random Random Number

(1) The seed of random numbers can be passed in the construction method;

(2) A sequence of pseudo-random numbers calculated from the seed of a random number;

(3) Nextint (maximum value);

(4) The default random number seed is the time value.

Packaging Implementation Method:

1  PackageOrg.hanqi.array;2 3 ImportJava.util.Random;4 5  Public classBaozhuang {6 7      Public Static voidMain (string[] args) {8         9         Ten         //Packing class OneLong l=NewLong (100); A          -         //turn a string into a numeric value -Long l1=NewLong ("1000"); the          -String str =1000+ ""; -          -         //turn from wrapper class to basic data type +         LongL2=L1.longvalue (); -  +System.out.println ("l2=" +L2); A  at         LongL3=long.parselong ("1200"); -          -          -         //int -Integer i=NewInteger ("100"); -          inInteger.parseint ("100"); -          to         //float +Float f=NewFloat ("123.45"); -          theFloat.parsefloat ("123.45"); *          $         //DoublePanax NotoginsengDouble d=NewDouble ("12345.67"); -          theDouble.parsedouble ("12345.67"); +          A         //Boolean theBoolean b=NewBoolean ("true"); +          - System.out.println (B.booleanvalue ()); $          $          -          -         //Math Tool Class the          - System.out.println (Math.PI);Wuyi          the         //Rounding -System.out.println (Math.Round (1234.56789)); Wu          -         Doublede=1234.56; About          $         //Keep 2 digits after the decimal point -System.out.println (Math.Round (de*100)/100.0); -          -         //The number after the decimal point. A          +         //Lower Value: The largest integer less than or equal to it the System.out.println (Math.floor (DE)); -          $         //Upper Value: The smallest integer greater than or equal to it the System.out.println (Math.ceil (DE)); the          the          the         //between random number 0~1 -          in System.out.println (Math.random ()); the System.out.println (Math.random ()); the System.out.println (Math.random ()); About System.out.println (Math.random ()); the System.out.println (Math.random ()); the System.out.println (Math.random ()); the System.out.println (Math.random ()); +          - System.out.println (); the         BayiRandom r=NewRandom (); the          the         //random number seed -         //pseudo-Random number -         //based on the seed. the         //the generation sequence of random numbers determined by the seed the         //r=new Random (ten); the          the          for(intm=0;m<10;m++) -         { theSystem.out.println (R.nextint (30)); the         } the         94     } the}
Baozhuang

Packaging & Tool Classes

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.