控制语句

控制语句

1. 顺序结构 (最常见的)

特点:代码从上往下依次执行

2. 选择结构 :

      if 判断语句 :

      switch 判断语句:

      Switch语句使用的注意事项:

            1.每一个语句结束后需要有一个break,防止switch的穿透。

            2.switch语句中用于判断的额变量只能是int ,short,char,byte String(jdk7之后才有)

            3.Case后面跟的数据必须是常量。

3.switch语句的优点 :语句结构清晰,运行速率快。

4.switch语句的缺点:If能做的switch不一定能做,switch能够做的if一定可以实现。

/*
	三目运算符:
	三元运算符:

	结构:
		
		条件?条件成立的结果 :条件不成立的结果 ;
*/
class Demo1 
{
	public static void main(String[] args) 
	{
		
		
		int a = 10;
		int b = 9;
		int c =  b++>=a ? a++ : b+a;
		System.out.println(a);  //10
		System.out.println(b);  //10
		System.out.println(c);  //20

	}

	
}

  

posted @ 2016-12-06 20:32  游家金  阅读(101)  评论(0)    收藏  举报