Java basic data Type (ii) and branching structure

Source: Internet
Author: User

basic data type (four classes of eight): cannot be null
One, integer type
byte----2 of 8 square
Short ----2 of the 16-time Square
int----2 of the 32-time Square
Long----2 of the 64-time Square
second, floating-point type
float----4 x
Double---8 bytes
Three, Boolean type
Boolean (True, False)
four, character type
char (can be a letter, or it can be a Chinese character)

int a = 5;
Save All to Stack
Reference type: String s = "abc";
all classes, arrays, interfaces

operator string The connection string needs to be noted: in the output, as long as one parameter is a string, the entire output is a string.
Xor operator: converted to binary form to compare each digit, not the same as 1, the same as 0

Priority of type conversion: double float long int chcar short byte

When a char short byte is evaluated, the value defaults to int

Implicit conversion (Low-"high") display conversion (high--low)

Branch
if (expression _ Boolean value) {
...
}

if (expression _ Boolean value) {
...
} else {
...
}

if (expression _ Boolean value) {
...
} else if (expression _ Boolean value) {
...
}

if (expression _ Boolean value) {
...
} else if (expression _ Boolean value) {
...
} else {
...
}

int a = 2;
switch (a) {
Case 1
...
Break ;
Case 3
...
Break ;
Case 5
...
Break ;

Default
...
}

The difference between if and switch

1, switch: must use break to end the loop, otherwise it will be infinite loop, if the condition does not meet the automatic end loop.

2, if: The result is the Boolean type of judgment

3, can use the switch to use if, the reverse is not

public class kehouzuoye1{

public static void Main (String args[]) {
int a = 3;
int c = 5-(a--); c=5-(3-1) =2
Boolean b = a = = C; B=false
b = B && (a < c--)?      False:true; B=false
int d = b?              7:9; D=9

int e = d-3; E=6
C *= 3; C=3

int f = ((++e = = c)? 25:35) + (++a); f=38

System.out.println (the value of "F:" + f);
}
}

 Public classkehouzuoye2{ Public Static voidMain (String args[]) {intA, B, C; A= c =8; b= a++;//b=8;a=9;          ShortD =3; Longe1 = d++ + A;//e1=12;d=4;        LongE2 = d++ + a++;//e2=13;d=5;a=10Boolean B1 =false; Boolean B2=!B1;//b2=true        floatg = b2? A:B;//g=10        Doubleh = g-=1;//h=g=9Boolean B3 = G = =Ten;//B3=false        Chars = b3?'a':'b';//s= ' B ' =98        inti =2* s;//i=2 ' B ' =186}}

Cycle
for (int i=0;i<10;i++) {
...
}

while (expression _ Boolean) {

}

do {

} while (expression _ Boolean value);

Java basic data Type (ii) and branching structure

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.