Using Java to understand program logic, variables

Source: Internet
Author: User

Data type Description Example
Int Integral type Used to store integers. For example. Number of trainees. Employee number of a company. The number of days in a year. Number of hours in a day
Double Double-precision floating-point type Used to store numbers with decimals. For example, the price of a commodity. The price of the world. The amount of loans the World Bank gives to other countries (regions). Employee wages
Char Character type Used to store a single character. e.g. male, female, score: gifted or poor
String String type Used to store a string of characters, such as employee name, product model, product introduction information

I. Data type

1. Data type variable name: (Syntax below)

Double score;//declare dual-precision floating-point variable score storage score

String name; Declare string variable name store student name

char sex; Declaring a character type variable sex storage gender

2. Variable assignment: (Syntax below)

Variable name = value;

score=98.5;//Storage 98.5

Name= "Zhang San";//Storage "Zhang San"

sex= ' Male '//store ' male '

3. Merge the (1). (2) steps

Data type variable name = value; (Syntax below)

Double score = 98.5;

String name = "Zhang San";

char sex = ' male '

4. Call the variable. That is, using stored variables is called calling variables.

SYSTEM.OU.PRINTLN (variable name);

Two. Variable naming rules

1. The variable must begin with a letter. Underscore "-" or "$";

2. Variables can include numbers. But cannot begin with a number;

3. In addition to the underscore "-". $ "Variable name cannot contain any special characters;

4. You cannot use keywords in java. such as Int,public,class.

Three. Java provides a variety of operators, as described below.

1. Assignment operator (=);

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

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

Four. Data type conversions are designed to facilitate operations between different types of data.

Five. Data type conversions include automatic type conversions and forced type conversions, which must meet certain conditions when automatic type conversions occur.

Six. Boolean types are used in Java to represent true and false. It has a value of two (true) (false).

Seven. The use of relational operators in Java can compare size, height, and so on, the result of comparison is a Boolean type.

Eight. Java provides the scanner class to obtain the information entered on the keyboard from the console.

Using Java to understand program logic, variables

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.