Variables, data types, and operators

Source: Internet
Author: User

 

 


I. Variables
1: variable definition: The expression of a bucket.
2: common Java Data Types
INT: integer. Used to store integers.
Double: Double Floating Point type. Stores decimal numbers.
CHAR: character type. Stores a single character.
String: string type. Stores a string of characters.
3: two ways to define variables:
01. Declare and assign values first
Example:
Int money; // declare a variable
Money = 100; // assign a value to the variable
02. simultaneous assignment of declarations
Example:
Int money = 100;
4: variable naming rules
01. It must start with a letter, underscore "_", or "$;
02. A number may exist, but cannot begin with a number;
03. No other symbols except the underscore "_" or "$;
04: you cannot use Java keywords for variable names, such as int, class, and public.
Generally, the first letter of a variable name is lowercase, And the last letter of a variable name is uppercase. (Camel naming method)
Ii. operators:
Expression definition: A combination of symbols and operands.
1: Value assignment operator: "=". Assign the result of the expression on the right of the equal sign to the variable on the left of the equal sign.
2: arithmetic operators:
+: Addition Operator
-: Subtraction Operator
*: Multiplication Operator
/: Division integer Operator
%: Division remainder Operator
3: ++ itself plus one;
-- Minus one;
++ Or -- before a variable: this means that the variable itself is first added and then involved in the operation.
+ + Or -- after the variable: it means that the variable is involved in the calculation first, and then added to itself.
Num + = 1: num = num + 1
Num + = 2: num = num + 2
4: Relational operators
>: Greater
<: Less
>=: Greater than or equal
<=: Less than or equal
=: Equal
! =: Not equal
5: logical operators
&: Corresponds
|: Or
! : Non (reverse)
Iii. Data type conversion:
Rule 1: If an operand is of the double type, the entire expression can be upgraded to the double type.
Example:
Int score = 80;
Double newscore = score;
The newscore output value is 80.0.
Rule 2: meets the conditions for automatic type conversion
01: the two types must be compatible;
02: The target type is greater than the source type.
Data type conversion can be divided:
(1) automatic data type conversion (amplification and conversion)
(2) Forced data type conversion: convert a type with a large width to a type with a small width (narrow conversion)
Example:
Double A = 84.5;
Int B = (INT) B/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.