1、循环结构
2、条件语句
3、switch case
4、实例
打印九乘九乘法表
public class Main {
public static void main(String[] args) {
for (int j = 1; j <=9; j++) {
for (int i = 1; i <= j; i++) {
System.out.print(i+ "*" + j + "=" + j*i+"\t");
}
System.out.println();
}
}
}
打印三角形
public class Main {
public static void main(String[] args) {
//for循环打印三角形
for (int i = 1; i <=5; i++) {
for (int j = 5; j>=i; j--) {
System.out.print(" ");
}
for (int j= 1; j<= i; j++) {
System.out.print("3");
}
for (int j = 1; j<=i; j++) {
System.out.print("3");
}
System.out.println();//换行打印
}
}
}