流程控制:打印三角形
打印等腰三角形:
public class Demo01 {
public static void main(String[] args) {
//打印等腰三角形
// *
// ***
// *****
// *******
// *********
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("*");
}
for (int j = 1; j < i; j++){
System.out.print("*");
}
System.out.println();
}
}
}
打印倒直角三角形:
import java.util.Scanner;
public class Demo02 {
//打印倒直角三角形
// *****
// ****
// ***
// **
// *
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j < i; j++){
System.out.print(" ");
}
for (int j = 5; j >= i; j--){
System.out.print("*");
}
System.out.println();
}
}
}
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术