Java Process Control Statements

Source: Internet
Author: User

public class Demo2 {
public static void Main (string[] args) {
Use of the IF statement: Multi-use for range judgments
int x=3;
int y=10;
System.out.println ("= = = Compare Start = = =");
if (x>y) {
System.out.println ("X>y");
}else{
System.out.println ("X<y");
}
System.out.println ("= = = = = = = = = = =");
Trinocular operator, maximum value
int max=0;
int x1=3;
int y1=10;
max=x1>y1?x1:y1;
System.out.println ("= = = 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 match to results");
}
Switch statement: Arithmetic, judging a few specific situations
int x3=6;
int y3=3;
Char oper= ' + ';
Switch (OPER) {
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 ("Cannot calculate operation");
Break
}
}
The While statement uses the
int x4=1;
int sum=0;
while (x4<=10) {
sum+=x4;
x4++;
}
System.out.println ("Accumulation of 1 to 10:" +sum);
System.out.println ("= = = Use Do...while notation = = =");
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+ "\ t");
}
}
Break: Leave 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 print above case = = =");
for (int q1=0;q1<=4;q1++) {
if (q1==3) {
Break
}
System.out.println ("q1=" +q1);
}
System.out.println ("= = = use for loop to print pyramid = = =");
for (int i=0;i>10;i++) {
System.out.println ("");
for (int j=i;j<7;j++) {
System.out.print ("*");
}
}
}


}

Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21

Java Process Control Statements

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.