java打出菱形的代码 java菱形怎么打( 三 )


for (int j = 1; j = (num - i); j++) {
System.out.print(" ");
}
// 打印*的个数
if (i == 1) {
System.out.print("*");
} else {
System.out.print("*");
// 打印菱形里的空格
for (int j = 1; j = (2 * i - 3); j++) {
System.out.print(" ");
}
System.out.print("*");
}
System.out.println();
}
}
private static void t6(int num) {
// 上半部分
for (int i = 1; i = num; i++) {
for (int j = 1; j = num - i; j++) {
System.out.print(" ");
}
for (int j = 1; j = 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
// 下半部分
for (int i = 1; i = num - 1; i++) {
for (int j = 1; j = i; j++) {
System.out.print(" ");
}
for (int j = 1; j = 2 * (num - 1 - i) + 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
private static void t5(int num) {
for (int i = num; i0; i--) {
for (int j = 1; j = num - i; j++) {
System.out.print(" ");
}
for (int j = 1; j = 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}
回答于 2022-12-14
java 怎样写出一个菱形程序?空心和实心java打印菱形通过二维数组来打?。道缦拢?
int hangshu = 11;
int yiban = hangshu / 2 + 1;
int yibanduo = hangshu / 2;
System.out.println("空心菱形:");
for(int k = 1;k = yiban;k++){
for(int i = 1;i = (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i = ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
for(int k = yibanduo;k =1;k--){
for(int i = 1;i = (yiban - k);i++){
System.out.print(" ");
}
System.out.print("*");
for(int i = 1;i = ( (k - 2) * 2 + 1);i++){
System.out.print(" ");
}
if(k != 1){
System.out.print("*");
}
System.out.println();
}
System.out.println("实心菱形:");
for(int i = 1;i = hangshu;i++){
if(i = hangshu/2 + 1){
for(int k = 1;k = hangshu/2 + 1- i;k++){
System.out.print(" ");
}
for(int k = 1;k = i;k++){
System.out.print("* ");
}
System.out.println();
}else{
for(int k =1;k = (i -(hangshu/2 + 1));k++){
System.out.print(" ");
}
for(int k = 1;k = (2 *(hangshu/2 + 1) - i);k++){
System.out.print("* ");
}
System.out.println();
}
}
结果如下:
关于java打出菱形的代码和java菱形怎么打的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读