1个回答
展开全部
public class test4 {
//打印正三角形
public static void sanjiaxing(){
//外层循环 控制轮数(行数)
for (int i = 1; i <= 5; i++) {
//打印空格
for (int j = 0; j <= 5 - i; j++) {
System.out.print(" ");
}
//打印“*”
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.println();
}
}
//打印倒立的三角形
for (int m = 1; m <= 4; m++) {
//打印空格
for (int n = 0; n <= m; n++) {
System.out.print(" ");
}
//打印*
for (int x = 1; x <= 7 -2 * (m - 1); x++) {
System.out.print("*");
}
System.out.println();
}
//菱形函数
public static void lingxing(){
for (int i = 1; i <= 5; i++) {
for (int j = 0; j <= 5 - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.println();
}
}
//主函数
public static void main(String[] args) {
//调用函数
lingxing();
}
}
//打印正三角形
public static void sanjiaxing(){
//外层循环 控制轮数(行数)
for (int i = 1; i <= 5; i++) {
//打印空格
for (int j = 0; j <= 5 - i; j++) {
System.out.print(" ");
}
//打印“*”
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.println();
}
}
//打印倒立的三角形
for (int m = 1; m <= 4; m++) {
//打印空格
for (int n = 0; n <= m; n++) {
System.out.print(" ");
}
//打印*
for (int x = 1; x <= 7 -2 * (m - 1); x++) {
System.out.print("*");
}
System.out.println();
}
//菱形函数
public static void lingxing(){
for (int i = 1; i <= 5; i++) {
for (int j = 0; j <= 5 - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.println();
}
}
//主函数
public static void main(String[] args) {
//调用函数
lingxing();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询