
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");
}
//第二种方式
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<b){
System.out.println("c小于b");
}
else {
System.out.println("c大于b");
}
}
}
枚举类
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里面的值比较
原文:http://www.cnblogs.com/linjingjia/p/7270668.html