阅读目录:
1.程序流程控制
顺序结构
判断结构
选择结构
循环结构
1.程序流程控制
程序流程控制:就是程序运行时候的控制。
顺序结构
class Demo2 { public static void main(String[] args) { System.out.println(‘hello world1‘) System.out.println(‘hello world2‘) System.out.println(‘hello world3‘) System.out.println(‘hello world4‘) } }
判断结构
格式1:
class Demo3 { public static void main(String[] args) { /* if 语句的第一种格式: (1) if (条件表达式) //要么真,要么假 { 执行语句; } 例子: int x = 3; if (x>1) { System.out.pritln("yes"); } System.out.println("over"); */ } }
格式2:
class Demo4 { public static void main(String[] args) { /* if 语句的第二种格式: (1) if (条件表达式) //要么真,要么假 { 执行语句; } else { 执行语句; } System.out.println("hello world"); 例子: int x = 3; if (x>1) { System.out.pritln("yes"); } else { System.out.pritln("no"); } System.out.println("over"); if (a>1) b=100; else b=200; b = a>1?100:200; //三元运算符就是if else 语句简写格式。 简写格式什么时候使用? 当if else 运算后有一个具体的结果时,可以简化写成三元运算符。 */ } }
格式3:
class Demo4 { public static void main(String[] args) { /* if 语句的第二种格式: (1) if (条件表达式) //要么真,要么假 { 执行语句; } else if (条件表达式) //如果前面为True,就不执行。 { 执行语句; } else // 如果前面有一个为True,都不执行。 { 执行语句; } System.out.println("hello world"); 例子: int x = 3; if (x>1) { System.out.pritln("a"); } else if (x>2) { System.out.pritln("b"); } else if (x>3) { System.out.println("c"); } else { System.out.println("d"); } System.out.println("hello world") */ } }
选择结构
循环结构
原文:https://www.cnblogs.com/zhongbokun/p/10508256.html