Jerry Education 4

Source: Internet
Author: User

Identifier

Basic requirements: composition, only by letter, number, _, $ symbol, the beginning cannot be a number.

Naming specification: Class name: The first letter of each word is capitalized, eg:helloworld (Big hump rule).

Variable, attribute, method name: First letter lowercase, followed by the first letter of each word capitalized, eg:myname (small hump rule). or My_name.

Identifiers must be named with semantics, as much as words.

All the colors in the code are keywords.

"Basic Data Type"

There are 6 languages in C and 8 in Java.

The 8 types in Java include:

Integer type (small to Large): Byte,short,int,long.

BYTE, 8 bits, short two bytes, int four bytes, long eight bytes.

Decimal type (floating point): float (single-precision floating-point number, 4 bytes, 6-7 digits),

Double (dual-precision floating-point number, 8-byte, 15-16-bit significant digit).

Single-precision operation is faster.

Character type: char (2 bytes), a number, a letter, a symbol is called a character.

Boolean: Boolean (used to judge right and wrong, true,false).

The C language does not have a Boolean and byte.

int num;//declaring a variable

num=1;//Assigning values to variables

int num=1;//declaring variable at the same time assignment value

float fnum=1.3f;

"Declaration of variables"

Flaot:float fnum=1.3f; The end must have f/f, cannot omit.

Double dnum=1.3; The end can be d/d, or it can be omitted.

Char c= ' A '; Char is represented by single quotation marks, only one letter, one number, and one symbol.

Boolean istrue=false; Boolean can be followed by true or false.

Data type Length (understanding): In int, for example, int is four bytes, 32 bits, and one of the -2^31 to 2^31-1,32 bits is a sign bit. One byte is 8 bits.

The length of all data types is fixed and does not vary depending on the hardware and software.

\ \ Escape character. Jerry \ \ Education, finally output Jerry's education.

Single quotation marks denote characters, and double quotation marks represent strings.

The final modified variable becomes constant and cannot be changed, and all letters of the constant name are capitalized. eg:final int num1=1;

"Basic Data type Conversions"

Automatic type conversion

Forcing type conversions

In addition to Boolean types, other basic data types can be converted.

Two conditions for automatic type conversion: 1. Two data types that are converted to each other are compatible, except for Boolean types, 2. Must be from low to high, must be converted from a small range of data types to a wide range, which can be automatically converted to meet these two conditions.

Data type size is arranged (from small to Large): Byte,short (char), int,long,float,double.

Double d=1; A double converted from a lower-level int to a higher level, with a output of 1.0

Coercion type conversions are converted by a large range of data types to a small range data type and must be cast.

int num2= (int) 1.7f; Cast by high-level float to lower int, output 1

Note: The numbers after the decimal point are automatically cast out, not rounded, and the type you want to convert is indicated in parentheses.

operator

1. Arithmetic operators

+-*/% of which,% indicates the remainder. 22/10=2 22.0/10=2.2, when both sides of the slash are integers, the result is an integer, and does not round, directly to the decimal point, when the slash on either side of any decimal, the result is a decimal.

System.out.println (1+2+ "3" +4+5+ "6"), the output is 33456. The plus sign has two functions: the addition operation and the link string, respectively. When the plus signs are all numbers, the addition operation is performed. When the plus sign has either side as a string, the link results in a string.

2. Relational operators

= = = > < >= <=

Note: = Indicates an assignment, = = equals

The result of the relational operator judgment can only be true or false, and there cannot be a third type.

Note: All symbols must be in English.

To determine if a number is in a certain range, you must use the && link. 500<=num&&num<=1000.

3. Logical operators (emphasis)

& (with), | (or), && (and), | | (or),! (non).

System.out.println (5&6); The output result is 4.

5 is converted to binary 101, 6 to binary 110, the same as 1, different to 0, the result is 100, and the result is 4.

&/&&: Both sides are true and the result is true.

|/|| : Both sides are false and the result is false.

The difference between & and &&:1.& can not only make logical judgments, but also perform bitwise operations, when both sides of the & are numbers, the bitwise operation;&& can only be logically judged and cannot be bitwise-operated. & called bitwise-and. 2. When both logical judgments are,&& called short-circuit and, short-circuit and from left to right judgment, when the first false judgment, then no longer judge the second, the direct output of the result is false. & is called logic and, regardless of whether the first result is true or false, the result of the second output is judged.

In summary: When making logical judgments, use && and | |.

4. Assignment operators

I+=1ài=i+1, but the former has a faster computational efficiency.

5. Single-Mesh operators

+ + self-increment operator--decrement operator

i++ài=i+1;

Similarities and differences of i++ and ++i:

The same point: whether i++ or ++i, after execution, the value of I will be added 1.

Different points: i++, first with the value of I to calculate, and then the value of I plus 1.

++i, first add the value of I to 1, and then the value of the operation.

int i,j,k;

i=5;

j=i++ +2;//j=7 i=6

K=++j +2;//j=8 k=10

System.out.println (i+ "/" +j+ "/" +k ");

The output result is 6/8/10.

int i,j,k;

i=5;

J=++i +2;//i=6 j=8

k=i++ +2;//k=8 i=7

System.out.println (i+ "/" +j+ "/" +k ");

The output result is 7/8/8.

6. Multi-mesh operator

A>b?true:false If the result in front of the question mark is true, execute the code preceding the colon, or execute the code after the colon if the result in front of the question mark is false.

An ASC code value of 65,a is 97,b with an ASC code value of 66,B with an ASC code value of 98.

The precedence of the operator, () is the highest, followed by the monocular operator, multiplication, plus and minus, greater than or equal to less than or equal to, equal to, not equal to, or, non, various assignment symbols.

With or at the same time, with a ratio or high.

In all languages, the priority of the assignment operator is always the lowest.

Input syso, press alt+/, can appear directly System.out.println ();

Place the cursor on the line you want to copy, press alt+ctrl+ down arrow to copy the row directly.

Place the cursor over the line you want to move, press CTRL + UP ARROW or DOWN ARROW to move the line.

For the sum of the numbers, for example: the sum of the sums of 8349 of the number of members.

8349%10 will take 8349 to 10 to get the remainder, the single digit 9.

(8349/10)%10 8349 divided by 10 results 834.9 to 10, resulting in 4.

(8349/100)%10 8349 divided by 100 results 83.49 to 10, resulting in 3.

8349/1000 divide 8349 by 1000 to get 8.

Scanner input=new Scanner (system.in); Input statement

int Num=input.nextint (); Enter an integer

Double d=input.nextdouble (); Enter double

String S=input.next (); Input string

2016.07.27

Try using shortcut keys!!!

Branching and looping

Three basic process structures common in Java: Sequential structure, selection structure (branching structure), and loop structure.

Loop structure: While statement, Do-while statement, for statement, foreach statement.

Jump statement: Break statement, continue statement, return statement.

"If-else Selection Structure"

if (1>2) {

System. out. println ("code executed when the condition is established");

} Else {

System. out. println ("If condition is not established, code executed");

}

The above will become a dead loop and should read:

int num=1;

if (NUM<2) {

System. out. println ("code executed when the condition is established");

} Else {

System. out. println ("If condition is not established, code executed");

}

In the IF-ELSE selection structure, special attention should be paid to indentation.

With the If-else statement, you can do it without a lot of eye arithmetic.

    1. If the parentheses after the if is the judging condition, the result of this condition must be true or false and must be a logical judgment.
    2. Curly braces {} must appear in pairs, indispensable.
    3. Curly braces {} cannot be saved, but else{} structures can be omitted, and if{} structures cannot be omitted.
    4. Code Indentation!!!

"Multiple if selection structure (also called ladder if, else-if structure)"

if (condition i) {

SYSTEM.OUT.PRINTLN ("Code executed at the time the condition is established");

}

else if (condition two) {

SYSTEM.OUT.PRINTLN ("Condition one not established, condition 20% immediately executes code");

System.out.println ("The ELSE-IF statement can have more than one");

}else{

SYSTEM.OUT.PRINTLN ("code executed when all conditions are not valid");

}

Input character: Char C=in.next (). charAt (0);

"Nested IF selection structure"

if{} inside the nested if{} structure.

Structure notation:

if (condition i) {

if (condition two) {

System.out.println ("Code of execution when condition I, condition II is established");

}else{

SYSTEM.OUT.PRINTLN ("code executed when conditions are established and conditions are not established");

}

}else{

SYSTEM.OUT.PRINTLN ("condition is not immediately executed code");

}

Note: Nested structures generally do not exceed three layers, can be solved with multiple if the problem is generally not nested.

Select the code you want to organize, right click "Source" à "Format", you can organize.

"Switch selection Structure"

Format: switch (constant expression) {

CASE constant 1:

Statement

Break

Case constant 2:

Statement

Break

·····

Default

Break

}

Precautions:

    1. The parentheses after switch must be a constant expression that evaluates to a specific result, and the computed constant result can be an integer, a character, a string.
    2. The constant values that follow the case must remain unique and vary.
    3. Break function: Jump out of the current switch structure, each case item, unless special needs, must have a break.
    4. The switch structure only judges the correct option once, and when the correct case item is encountered, it is no longer judged, so when the break is omitted, it causes the program to execute the code in all the case items in sequence, starting with the correct one.
    5. The switch structure is specifically used to determine the equivalent structure, and the execution efficiency is faster than if-else.
    6. Case items can be enclosed in curly braces, so the variables declared in each case entry take effect only in the current case item.

When all the exits are included in the case, default can be omitted.

A variable declared in a case item is only useful in the current case item, but a different case item cannot declare a variable repeatedly.

Learn to make choices in if-else and switch when you see a problem.

Jerry Education 4

Related Article

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.