package Collection;import org.omg.CORBA.SystemException;public class ifexpression { public static void main(String[] args) { //if表达式针对布尔表达式或者boolean值 //第一种方式 int a=5; int b=7; int c=84; if(a b){ System.out.println("a大于b"); } else { System.out.println("a小于b"); } //第三种方式 if (a>b) { System.out.println("a大于b"); } else if(c
枚举类
package Collection;import java.util.Scanner;public class Switchexpression { //枚举类型 enum season{ spring,hot,fall,winner }; public static void main(String[] args) { // TODO Auto-generated method stub // //此处是整数值// Scanner scanner=new Scanner(System.in);// int int1=scanner.nextInt();// switch(int1)// {// case 1:// {// System.out.println("A");// break;// }// case 2:// {// System.out.println("B");// break;// }// default:// {// System.out.println("stop");// }// // //85// // stop season tianqi=season.fall; switch(tianqi) { case spring: { System.out.println("春天"); break; } case fall: { System.out.println("秋天"); break; } default: break; } } }
其中需要注意的是:1 枚举类的用法 2 switch语句的基本格式 3要注意break,如果break不写,程序可能会跟每个case里面的值比较
While:
while循环样式
[init_statement]while(text_expression){ statement; [iteration_statment]}
package Collection;public class Whileexpression { public static void main(String[] args) { int count=5; while(count>3) { System.out.println(count+"大于3"); count--; } System.out.println("结束"); /* * 5大于3 4大于3 结束 */ }}
do while:
do while样式
init_statement;do{ statement; [iteration_statement];}while(text_statement);
package Collection;public class dowhilexpression { public static void main(String[] args) { int count=5; do { System.out.println("count:"+count); count++; } while(count<10); /* * count:5 count:6 count:7 count:8 count:9 */ }}
break:
package Collection;public class breakexpression { public static void main(String[] args) { //break循环 outer: for(int i=0;i<10;i++) { System.out.print(i+"+"); // 1c此处打break break; 此时结果为0 // // if(i==2)// {// 2此处打break break;// }// /*// * 0// 1// 2// */ for(int j=1;j<5;j++) { System.out.print(j); break outer; } System.out.println(" "); } }}
continue:
package Collection;public class continueexpression { public static void main(String[] args) { // TODO Auto-generated method stub\ outer: for (int j = 0; j < 5; j++) { for(int i=0;i<10;i++) { System.out.println("i的值为 "); if(i==3) { System.out.println("connitue"); continue outer; } System.out.println(i); } } }}
return:
package Collection;public class returnexpression { public static void main(String[] args) { for(int j=0;j<10;j++) { for(int i=0;i<5;i++) { System.out.println(i); if(i==3) { System.out.println("Game over"); return; /* * 0 1 2 3 Game over */ } } } }}