Java Basics (2)

Source: Internet
Author: User
Tags arithmetic operators

One, variable

    1. A variable is an identifying symbol in memory that is used to store data
    2. Variable naming rules--"P35 page"

2.1 Must start with a letter, underscore, dollar sign

2.2 Variables, you can include numbers

2.3 variable, cannot appear special symbol, space

2.4 keyword in Java (red font), cannot do variable name

3. Variable name, followed by camel nomenclature (variable consists of more than 1 words, the first letter of the 1th Word lowercase, the first letter of the following words capitalized)

Ii. Types of data

A) number (integer int, decimal double)

b) character (char), storing a single character

c) string, storing multiple characters

Iii. How to declare variables and assign values to variables (Assignment operator =)

Method 1: Declare first, then assign value

Grammar:

Data type variable name;

Variable name = value;

Method 2: Assign a value directly when declaring a variable

Grammar:

Data type variable name = value;

Remember: Variables are declared first, then assigned, and then used

Iv. input data from the keyboard

Step 1: In the first line of the current code file, import the package

Import java.util.*;

or

Import Java.util.Scanner;

Step 2: Write the statement (write only once)

Scanner input=new Scanner (system.in);

Step 3: Define the variables and save the data entered by the keyboard

Data type variable name =input.next data type ();

Five, arithmetic operators

+ 、-、 * (multiplication sign)

/(Division sign, pick-up)

% (take the remainder, take the mold)

Special operators: + + ( gaga ) , --( minus and minus )

int a=1; a+=10; equal to a=a+10;

a-=5; equal to a=a-5;

int a=1;

Scene 1:system.out.print (a++);//Output 1

int a=1;

Scene 2:system.out.print (++a);//Output 2

Vi. Relational operators

Greater than sign:>

Less than number:<

greater than or equal to: >=

less than equals: <=

equals sign: ==

not equal to: !=

Seven, Boolean data types

  

Boolean: A value of TRUE or False

Assignment value:

The Boolean variable name =true or false or an expression;

Eight, Data type Conversions ( for numeric types )

1. Divided into 2 major categories:

numeric type (int, double),

Non-numeric type (character ', String ', Boolean type bool)

21. Data Type Conversion classification

A) automatic type conversion--"P41 page"

I. Rule 1:

ii. Rule 2:

int a value of type, saved to Double type of variable in

b) Coercion type conversion

Target type variable name = (target type) variable or expression;

A value of type double, saved to the INT type variable

int variable name = (int) A value or variable of type double;

Java Basics (2)

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.