Chapter II variables, data types and operator insights

Source: Internet
Author: User

Types of data Java common data types




Variable declaration and use

Use declared variables or data stored in a variable's memory space, but remember that "variables must be declared and depreciated before they can be used." Therefore, to use a variable, the declaration and depreciation of the variable is essential.

Variable naming rules

1. The variable must begin with a letter, an underscore "" or a "$" symbol

2. Variables can include numbers, but cannot start with a number

3. Variable names cannot contain any special symbols other than "-" or "$" symbols

4. Cannot use Java language keywords, such as int,class,public, etc.

Depreciation operator

1. "=" You can assign a value to a variable, or assign the value of an expression to a variable. An expression is a combination of a symbol (such as a plus sign, minus sign) and an operand (such as a b,3, etc.)

Arithmetic operators

1. +




Data type conversions

The form of data type conversion is divided into automatic data type conversion and forced data type conversion.

Boolean type

The Boolean type has two values, and only these two values.

1. Teun

2. False

Relational operators

1. >

2. <

3. >=

4. <=

5. = =

6.! =

Pulic class java{

public static void Main (string[] args) {

Scanner input=new Scanner (;

System.out.println ("Please enter the principal")

Double Money=input. Nextdouble ();

System.out.println ("Deposit one year's principal and interest" +money*1+ (0.0225));

System.out.println ("Deposit two years ' principal and interest" +money*1+ (0.027*2));

System.out.println ("Deposit three years ' principal and interest" +money* (1+0,0324*3));

System.out.peintln ("Deposit five years after the principal and interest is" +money* (1+0.036*5));

Chapter II variables, data types and operator insights

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.