Java Process Control statements

Source: Internet
Author: User

Java Process Control statements
Public class Demo2 {
Public static void main (String [] args ){
// If statement usage: mostly used for range judgment
Int x = 3;
Int y = 10;
System. out. println (=== comparison start === );
If (x> y ){
System. out. println (x> y );
} Else {
System. out. println (x }
System. out. println (=== comparison ended === );
// Calculate the maximum value of the Three-object Operator
Int max = 0;
Int x1 = 3;
Int y1 = 10;
Max = x1> y1? X1: y1;
System. out. println (=== the maximum value is + max );
// If, else if, judgment statement
Int x2 = 3;
If (x2 = 1 ){
System. out. println (the value of x2 is 1 );
} Else if (x2 = 2 ){
System. out. println (the value of x2 is 2 );
} Else if (x2 = 3 ){
System. out. println (the value of x2 is 3 );
} Else {
System. out. println (no matching results );
}
// Switch statement: Four arithmetic operations to determine specific situations
Int x3 = 6;
Int y3 = 3;
Char character = '+ ';
Switch (switches ){
Case '+ ':{
System. out. println (x3 + y3 = + (x3 + y3 ));
Break;
}
Case '-':{
System. out. println (x3-y3 = + (x3-y3 ));
Break;
}
Case '*':{
System. out. println (x3 * y3 = + (x3 * y3 ));
Break;
}
Case '/':{
System. out. println (x3/y3 = + (x3/y3 ));
Break;
}
Default :{
System. out. println (calculation operation unavailable );
Break;
}
}
// Use the while statement
Int x4 = 1;
Int sum = 0;
While (x4 <= 10 ){
Sum + = x4;
X4 ++;
}
System. out. println (the sum from 1 to 10: + sum );
System. out. println (=== use do... while to write = );
Int x5 = 1;
Do {
Sum + = x5;
X5 ++;
}
While (x5 <= 10 );
System. out. println (do... while: sum = + sum );
// Process control statement: for Loop
Int sum1 = 0;
For (int x6 = 0; x6 <= 10; x6 ++ ){
Sum1 + = x6;
}
System. out. println (for statement: sum1 = + sum1 );
System. out. println (=== double for loop print multiplication table );
For (int i1 = 1; i1 <= 9; i1 ++ ){
System. out. println ();
For (int j = 1; j <= i1; j ++ ){
System. out. print (i1 + * + j + = + i1 * j + );
}
}
// Break: exit the current loop
System. out. println (======= );
For (int q = 0; q <10; q ++ ){
If (q = 3 ){
Break;
}
System. out. println (q = + q );
}
System. out. println (=== use continue to print the above case === );
For (int q1 = 0; q1 <= 4; q1 ++ ){
If (q1 = 3 ){
Break;
}
System. out. println (q1 = + q1 );
}
System. out. println (===use for loop print pyramid === );
For (int I = 0; I> 10; I ++ ){
System. out. println ();
For (int j = I; j <7; j ++ ){
System. out. print (*);
}
}
}


}

 

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.