1、流程控制语句的介绍
1.1 概念:
1.2 分类:
2、顺序结构
3、分支结构
3.1 if语句
3.1.1 if的第一种格式
3.1.2 if的第二种格式
3.1.3 if的第三种格式
3.1.4 if的注意事项
3.2 switch语句
3.2.1 switch格式和说明
案例:
4、循环结构
4.1 for循环格式的介绍
4.1.1 for循环语句的注意事项:
案例:打印九九乘法表格:
package com.itheima.mfor;
public class Demo {
public static void main(String[] args) {
print9x9();
}
public static void print9x9(){
for(int i = 1; i <= 9; i++){
for(int j = 1; j <= i; j++){
System.out.print(j + "*" + i + "=" + i * j + "\t");
}
System.out.println();
}
}
}
4.2 while循环格式与执行流程
4.2.1 while循环
4.2.2 do…while循环
4.3 三种循环的区别
5、跳转控制语句
5.1 break语句
5.2 continue语句
注意:
6、Random介绍
6.1 Random的使用步骤
要是想要1-100之间的随机数怎么写?
答:
package com.itheima.mrandom;
import java.util.Random;
public class RandomDemo {
public static void main(String[] args) {
int i = randomTest(100);
System.out.println(i);
}
public static int randomTest(int num){
Random r = new Random();
int i = r.nextInt(num) + 1;
return i;
}
}