求大神帮我讲解下这道java 编程题。题目如下。另外再打印输出一个等腰三角形。外加一个直角三角形。
求大神帮我讲解下这道java编程题。题目如下。另外再打印输出一个等腰三角形。外加一个直角三角形。本人是刚开始学Accp初级软件开发的菜鸟。帮我使用for双重循环结构实现!...
求大神帮我讲解下这道java 编程题。题目如下。另外再打印输出一个等腰三角形。外加一个直角三角形。本人是刚开始学A ccp 初级软件开发的菜鸟。帮我使用for 双重循环结构实现!重谢。看图!
展开
展开全部
for (int row = 0; row < 5; row++) {
for (int col = 1; col <= 2 * row - 1; col++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("正的直角三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 5; col >= 2 * row - 1; col--) {
System.out.print("*");
}
System.out.println();
}
System.out.println("倒的直角三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 5 - row; col++) {
System.out.print(" ");
}
for (int col = 0; col < 2 * row - 1; col++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("正的等腰三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 0; col <= row; col++) {
System.out.print(" ");
}
for (int col = 5; col >= 2 * row - 1; col--) {
System.out.print("*");
}
System.out.println();
}
System.out.println("倒的等腰三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 5; col > row; col--) {
System.out.print(" ");
}
for (int col = 0; col <= row; col++) {
System.out.print("* ");
}
System.out.println();
}
System.out.println("正的加空格等腰三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 1; col <= row; col++) {
System.out.print(" ");
}
for (int col = 5; col > row; col--) {
System.out.print("* ");
}
System.out.println();
}
System.out.println("倒的加空格等腰三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 5; col > row; col--) {
System.out.print(" ");
}
for (int col = 0; col <= row; col++) {
System.out.print("* ");
}
System.out.println();
}
for (int row = 1; row < 5; row++) {
for (int col = 0; col <= row; col++) {
System.out.print(" ");
}
for (int col = 5; col > row; col--) {
System.out.print("* ");
}
System.out.println();
}
System.out.println("实的菱形");
System.out.println("-------------------------------------------------");
for (int row = 1; row <= 5; row++) {
for (int col = 5; col >= row; col--) {
System.out.print(" ");
}
for (int col = 1; col <= 2 * row - 1; col++) {
if (col == 1 || col == 2 * row - 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (int row = 1; row <= 5; row++) {
for (int col = 1; col <= row + 1; col++) {
System.out.print(" ");
}
for (int col = 1; col <= 2 * (4 - row) + 1; col++) {
if (col == 1 || col == 2 * (4 - row) + 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println("空的菱形");
System.out.println("-------------------------------------------------");
for (int row = 1; row <= 5; row++) {
for (int col = 5; col >= row; col--) {
System.out.print(" ");
}
for (int col = 1; col <= 2 * row + 7; col++) {
// 判断行数是第一行要奇数打*
if (row == 1 && col % 2 == 1) {
System.out.print("*");
// 判断行数是第一行要偶数打空格
} else if (row == 1 && col % 2 == 0) {
System.out.print(" ");
// 判断行数是第一行和最后一行打*
} else if (col == 1 || col == 2 * row + 7) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (int row = 1; row <= 4; row++) {
for (int col = 1; col <= row + 1; col++) {
System.out.print(" ");
}
for (int col = 1; col <= 2 * (8 - row) + 1; col++) {
if (row == 4 && col % 2 == 1) {
System.out.print("*");
} else if (row == 4 && col % 2 == 0) {
System.out.print(" ");
} else if (col == 1 || col == 2 * (8 - row)+ 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println("掏空的六边形");
System.out.println("----------------------------------------------");
}
这些是打印图形的循环,你自己去找对应要的,你的图片真的看不清,不过你看完这些打印图形的代码估计就应该差不多自己能写出来了。希望能帮到你!
for (int col = 1; col <= 2 * row - 1; col++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("正的直角三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 5; col >= 2 * row - 1; col--) {
System.out.print("*");
}
System.out.println();
}
System.out.println("倒的直角三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 5 - row; col++) {
System.out.print(" ");
}
for (int col = 0; col < 2 * row - 1; col++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("正的等腰三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 0; col <= row; col++) {
System.out.print(" ");
}
for (int col = 5; col >= 2 * row - 1; col--) {
System.out.print("*");
}
System.out.println();
}
System.out.println("倒的等腰三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 5; col > row; col--) {
System.out.print(" ");
}
for (int col = 0; col <= row; col++) {
System.out.print("* ");
}
System.out.println();
}
System.out.println("正的加空格等腰三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 1; col <= row; col++) {
System.out.print(" ");
}
for (int col = 5; col > row; col--) {
System.out.print("* ");
}
System.out.println();
}
System.out.println("倒的加空格等腰三角形");
System.out.println("-------------------------------------------------");
for (int row = 0; row < 5; row++) {
for (int col = 5; col > row; col--) {
System.out.print(" ");
}
for (int col = 0; col <= row; col++) {
System.out.print("* ");
}
System.out.println();
}
for (int row = 1; row < 5; row++) {
for (int col = 0; col <= row; col++) {
System.out.print(" ");
}
for (int col = 5; col > row; col--) {
System.out.print("* ");
}
System.out.println();
}
System.out.println("实的菱形");
System.out.println("-------------------------------------------------");
for (int row = 1; row <= 5; row++) {
for (int col = 5; col >= row; col--) {
System.out.print(" ");
}
for (int col = 1; col <= 2 * row - 1; col++) {
if (col == 1 || col == 2 * row - 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (int row = 1; row <= 5; row++) {
for (int col = 1; col <= row + 1; col++) {
System.out.print(" ");
}
for (int col = 1; col <= 2 * (4 - row) + 1; col++) {
if (col == 1 || col == 2 * (4 - row) + 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println("空的菱形");
System.out.println("-------------------------------------------------");
for (int row = 1; row <= 5; row++) {
for (int col = 5; col >= row; col--) {
System.out.print(" ");
}
for (int col = 1; col <= 2 * row + 7; col++) {
// 判断行数是第一行要奇数打*
if (row == 1 && col % 2 == 1) {
System.out.print("*");
// 判断行数是第一行要偶数打空格
} else if (row == 1 && col % 2 == 0) {
System.out.print(" ");
// 判断行数是第一行和最后一行打*
} else if (col == 1 || col == 2 * row + 7) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (int row = 1; row <= 4; row++) {
for (int col = 1; col <= row + 1; col++) {
System.out.print(" ");
}
for (int col = 1; col <= 2 * (8 - row) + 1; col++) {
if (row == 4 && col % 2 == 1) {
System.out.print("*");
} else if (row == 4 && col % 2 == 0) {
System.out.print(" ");
} else if (col == 1 || col == 2 * (8 - row)+ 1) {
System.out.print("*");
} else {
System.out.print(" ");
}
}
System.out.println();
}
System.out.println("掏空的六边形");
System.out.println("----------------------------------------------");
}
这些是打印图形的循环,你自己去找对应要的,你的图片真的看不清,不过你看完这些打印图形的代码估计就应该差不多自己能写出来了。希望能帮到你!
更多追问追答
追问
请问一下,这个不用设条件?直接for 双重循环?
追答
不用的,你不是给了 row<5 那么col自动就有条件了 你再看看
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询