Java learning notes-data types, operators, and control statements

Source: Internet
Author: User
Tags array definition

I will talk about the differences between Java and C ++ I have learned before.

1. identifier: the identifier starting with $ in Java

2. Reserved Words: the number of reserved words is 48, no column, all of which are lowercase letters.

3. Data Type:

(1) boolean type: Boolean; values: true and false, which do not correspond to integers.

(2) A single character char occupies 16 digits in the machine, ranging from 1 ~ 65535. The C language is 8 bits. This is because the char in Java can represent Unicode characters in the form of '\ U ???? ',? Is a number.

(3) The integer type is not the same. The byte type, 8 bits, range:-2 ^ 7 ~ 2 ^ 7-1, short is 16 bits, Int Is 32 bits, long is 64 bits

(4) floating point type: It can be expressed by scientific notation, such as 123e3 and 1.2e5. A number is followed by a float value of f or F, and a value of D or D is double. The default value is double.

(5) string is a string class. It is similar to a class on C ++ and can be directly assigned a value.

(6) The basic data types all have their corresponding packaging classes. The purpose of introducing the packaging classes is as follows:

① Convert the basic data type to an object (the parameters of some class methods must be of the object type)

② Some static methods of the packaging class can realize conversion of different types, such as int A = integer. parseint ("123") converts "123" to an integer. String c = string. valueof (123) converts an integer to a string.

③ The static attribute of the class contains the range of data types, for example, integer. min_value is the minimum value of Int.

(7) constants are implemented with the reserved word final: for example, final int num = 100;

4. The remainder of 3.14% 2 is 1.140000001

5. Floating Point Number: Math. Round (5.6) is rounded to the nearest integer, Ceil is used to take the cursor, and floor is used to take a small value.

6. relational operations =,> and other results are boolean values, true or false.

7. & for operation, & for operation, the difference is: & and | during execution, both sides of the operator are executed first, and then followed by, or, & | if the result can be obtained from the left side, it is not counted as the right side. It is the same as that on C and C ++, and the efficiency ratio is higher than & and |. ^ Exclusive or

8. bitwise operation :~ Bitwise inversion, & bitwise AND, | bitwise OR, ^ bitwise XOR, <left shift,> right shift

9. If there is a break lab statement, the lab label must be negotiated in front of the entry statement of the External Loop.ProgramThe external loop of the exit label. The continue lab is similar.

10. No executable statements can be followed by return; otherwise, the compilation is incorrect.

11. The array definition method is slightly different: int A [] or Int [];

12. initialization: like C ++, use new, for example, a = new int [10]; or Int [] A = {3, 4, 5, 6}. The object array can be written like this: integer results [] = [New INTEGER (3), new ingeter (5 )};

Float f [] = new float [] {1.0f, 2.0f, 3.0f };

13. Two-dimensional array: int arr [] []; or Int [] [] arr; initialize arr = new int [3] [4];

Try againCodeTo determine the leap year

Public Class Leapyear
{
Public Static Void Isleapyear ( Int Year ){
Boolean N1 = (Year % 4 = 0 );
Boolean N2 = (Year % 100 = 0 );
Boolean N3 = (Year % 400 = 0 );
If (N1 = True & N2! = True ) | (N2 = True & N3 = True ))
{System. Out. println (Year + "");}
Else
{System. Out. println (Year + "not a leap year ");}
}
Public Static Void Main (string ARGs []) {
Isleapyear (1900 );
Isleapyear (1904 );
Isleapyear (2000 );
}

}

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.