//条件结构:简单的if语句、多重if。。else语句 笔记
import java.util.Scanner;//JDK自带的工具,需要时要导入
public class IfDemo
{
public static void main(String arg[]){
//列1
int cash=500;
char currency='$';
//最简单的语句
//当if语句块中只有一条指令的时候可以省略大括号(不推荐使用)
if(cash==500){
System.out.println("一定是在做梦");
}
System.out.println("哈哈");
if(cash>=500){
System.out.println("买别墅");
}else{
System.out.println("买公寓");
}
//列2
int a=10;
int b=1;
int c;
/*
if(a<b){
c=a;
}else{
c=b;
}
System.out.println(c);
*/
//条件表达式,if。。。。else的化简语句
//列3
c=(a<b)?a:b;
//括号中条件成立执行冒号之前的,不成了执行之后的
System.out.println(c);
//列4
if(cash>=500){
if(currency=='$'){
System.out.println("买独栋别墅");
}else{
System.out.println("买联排别墅");
}
}else{
System.out.println("买公寓");
}
//列5:多重if。。else语句
//多重形式的时候;条件顺序要考虑清楚,不能随意安排
if(cash>500){
System.out.println("买在1环");
}else if(cash>300){
System.out.println("买在2环");
}else if(cash>200){
System.out.println("买在3环");
}else if(cash>100){
System.out.println("买在郊区");
}else{
System.out.println("努力赚钱");
}
//列6
Scanner input=new Scanner(System.in);//标准键盘输入流
System.out.println("输入假期天数");
int holidays=input.nextInt();//获取键盘输入整数
//程序执行时会在这里暂停等待键盘输入
if(holidays>5){
System.out.println("去海南玩!");
}else if(holidays>3){
System.out.println("去周边玩!");
}else{
System.out.println("在家休息!");
}
}
}