Use java to understand program logic, variables, and java to understand logical variables

Source: Internet
Author: User

Use java to understand program logic, variables, and java to understand logical variables

Data Type Description Example
Int Integer Used to store integers. For example. Number of trainees. Employee ID of a company. The number of days in a year. Hours per day
Double Dual-precision floating point Stores decimal numbers. For example, the price of a product. World price. The amount of loans the World Bank has made to other countries (regions. Employee Salary
Char Character Type Stores a single character. For example, male and female. Score: Excellent or poor
String String type Stores a string of characters, such as employee name, product model, and product introduction information.

 

 

 

 

 

 

 

 

I. Data Types

1. Data type variable name: (syntax is as follows)

Double score; // declares the storage score of the double Precision Floating Point variable score.

String name; // declare the String variable name to store the Student name

Char sex; // declare the gender of the sex storage variable of the character type.

2. Variable assignment: (syntax)

Variable name = value;

Score = 98.5; // storage 98.5

Name = "James"; // store "James"

Sex = 'male' // store 'male'

3. Combine steps (1). (2) into one

Data type variable name = value; (syntax is as follows)

Double score = 98.5;

String name = "zhangsan ";

Char sex = 'male'

4. Call variables. The stored variables are called call variables.

System. ou. println (variable name );

Ii. variable naming rules

1. The variable must start with a letter. Underline "-" or "$;

2. variables can contain numbers, but cannot start with numbers;

3. Except for the underscore "-". "$", the variable name cannot contain any special characters;

4. Keywords in JAVA cannot be used. Such as int, public, class.

Iii. java provides various operators as follows.

1. Value assignment operator (= );

2. Arithmetic Operators (+,-, *,/, % );

3. Relational operators (>. >=. <. <=. = .! =)

4. Data type conversion is used to facilitate computation between different types of data.

5. Data type conversion includes automatic type conversion and forced type conversion. certain conditions must be met when automatic type conversion occurs.

6. Use the boolean Type in java to indicate true or false. The two values are (true) (false ).

7. In java, Relational operators can be used to compare the size, height, and quantity. The comparison result is of the boolean type.

8. java provides the category class to obtain information entered on the keyboard from the console.

 

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.