Int type package Integer, int type integer

Source: Internet
Author: User

Int type package Integer, int type integer

1. Integer Overview

Requirement 1: Calculate the binary, octal, and hexadecimal values of the 100 data.
Requirement 2: Determine whether a data is within the int range.
First, you need to know the int range?

To perform more operations on basic data types and facilitate operations, Java provides the corresponding class types for each basic data type. Packaging type.

Class type packaging class type

Byte Byte
Short Short
Int Integer
Long Long
Float Float
Double Double
Char Character
Boolean Boolean

Converts the basic data type to a string.

Public class IntegerDemo {public static void main (String [] args) {// No problem. // public static String toBinaryString (int I) System. out. println (Integer. toBinaryString (100); // public static String toOctalString (int I) System. out. println (Integer. toOctalString (100); // public static String toHexString (int I) System. out. println (Integer. toHexString (100); // public static final int MAX_VALUESystem.out.println (Integer. MAX_VALUE); // public static final int MIN_VALUESystem.out.println (Integer. MIN_VALUE );}}


2. Integer constructor:
Public Integer (int value)
Public Integer (String s)
Note: This string must be composed of digits.

Public class IntegerDemo {public static void main (String [] args) {// method 1int I = 100; Integer ii = new Integer (I); System. out. println ("ii:" + ii); // method 2 String s = "100"; // NumberFormatException // String s = "abc "; integer iii = new Integer (s); System. out. println ("iii:" + iii );}}

 

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.