Some important and practical foundations of JAVA [2]

Source: Internet
Author: User

Chapter 2 variables, data types, and operators:

1. Common Java data types:

Int is used to store integers, such as the number of students.

Double floating point is used to store decimal places such as the price of goods

The char character type is used to store a single character, such as gender.

String is used for a String of characters, such as employee name.

2. variable naming rules:

A: The variable must start with a letter, underscore, "_", or "$ ".

B: A variable can contain numbers, but cannot start with a number.

C: Except for the '_' or '$' symbol, variable names cannot contain any special characters.

D: You cannot use keywords in Java, such as int, class, or public.

3. The variable name must be short and clear, and can be composed of one or more words. Generally, the first letter of a word is lowercase, And the last letter of a word is capitalized.

4. Common arithmetic operators:

+ Addition operator, Sum

-Subtraction operator, Difference Calculation

* Multiplication operator, product

/Division calculation method, quotient

% Return the remainder operator and return the remainder.

5. boolean value:

True

False

6. Relational operators:

> Greater

<Less

> = Greater than or equal

<= Less than or equal

= Equal

! = Not equal

7. Value assignment operator: = value assignment

8. Three-Step statement for entering data from the console:

Import java. util. collections;

Wrote input = new partition (System. in );

Int stb = input. nextInt ();

9. Automatic type conversion:

Rule 1: If an operand is of the double type, the entire expression can be upgraded to the double type.

Rule 2: meets the conditions for automatic type conversion

Forced data type conversion: converts a type with a large width to a type with a small width, which causes data loss of precision"

 

 

    

 

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.