Java hands-on brain

Source: Internet
Author: User Program:

Package Damo;

Public class enumtest {


Public Static void Main (string[] args) {

Size s=size. SMALL;

Size t=size. LARGE;

S and T refer to the same object? False

System.  out. println (s==t); //

is the original data type? False

System. out. println (S.getclass (). isprimitive ());//Determine what data type

Convert from String

Size u=size. valueOf ("SMALL");//Assign the value of SMALL to u

System.  out. println (S==u); True

List all of its values

for (Size value:size. Values ()) {//traversal

System. out. println (value);



enum Size{small,medium,large};


Run results

First Judge S==t? The output is false, the second determines whether it is the original data type, not the original data type, FALSE, and the third s means that SMALL assigns SMALL to U,u=s,ture; 第四、五、六个 is traversal, size{small,medium,large} There are three data in it, so the traversal is three data.


An enumeration is not part of the original data type, and each of its specific values refers to a specific object. The same value references the same object

2. Binary of numeric value

The number is represented in binary form in the computer.
The number is divided into signed number and unsigned number.
The original code, the inverse code, the complement are the symbolic fixed-point number representation method.

The original code is the binary form of the number itself. Positive anti-code and complement are the same as the original code, negative anti-code is the original code in addition to the symbol bit outside the counter, the complement of the negative is the original code in addition to the sign bit after you seek to reverse in the end plus 1. Program

SOURCE program:

Package Damo;

Public class testdouble {

Public Static void Main (String args[]) {

System. out. println ("0.05 + 0.01 =" + (0.05 + 0.01));

System. out. println ("1.0-0.42 =" + (1.0-0.42));

System. out. println ("4.015 * 100 =" + (4.015 * 100));

System. out. println ("123.3/100 =" + (123.3/100));




Analysis: A numeric value of type Double is used to calculate the result is imprecise

Why the numeric value of a double type cannot be calculated as a "mathematically accurate" result

In Java, the double type data is represented by a 64-bit, and the precision is certainly finite, and the floating-point number is a numeric representation of a particular subset of the rational number, which is used to approximate any real numbers in a computer. Specifically, the real number is obtained by multiplying an integer or fixed-point number (that is, the mantissa) by a radix (usually 2 in the computer), which is similar to the scientific notation of cardinality 10. There are two ways to refer to the operations that require higher precision: 1. Use more than 64 bits to represent a double type, such as 100 byte[] to represent a double (800bytes), in which case the double subtraction needs to be implemented by itself. Many IT companies have this kind of face test. 2. It is easy to do high-precision operation with the BigDecimal class which comes with Java. (There is no class in C + + that bigdecimal this aspect, so you can only use the first method)


int x=100;


System.out.println ("x+y=" +x+y);

System.out.println (x+y+ "=x+y");

Program Results

Cause: +x+y represents the continuous output of the values of X and Y, and the second represents a two number addition

Java hands-on brain

Related Article

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: 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.