A:有咋样的实力可以写出这个代码?
B:会for循环就好
A:只要会for就好?
B:还有一点点逻辑能力和算法
package 海绵hong;
import java.util.Scanner;
public class text9 {
public static void main(String[] args) {
Scanner hong=new Scanner(System.in);
System.out.println("圣诞快乐!祝你早日脱单(有对象的话请不要说话,我喜欢你们保持沉默!!!)");
System.out.println("请输入你最喜欢的数字:");
int n=hong.nextInt();
shu(n);
}
public static void shu(int n) {
for (int i = 0; i <= n; i++) {
for (int b = n - i; b > 0; b--) {
System.out.print(" ");
}
for (int j = 0; j <= 2 * i; j++) {
System.out.print("*");
}
System.out.println();
}
for (int s = 0; s <= (n << 1) / 3; s++) {
for (int t = 0; t < 2 * n; t++) {
if ((t == 2 * n / 6 || t == 2 * n - (2 * n / 6)) && s < n/5)
System.out.print("¥");
else
System.out.print(" ");
}}
System.out.println("");
for (int i = 0; i <= n; i++) {
for (int b = n - i; b > 0; b--) {
System.out.print(" ");
}
for (int j = 0; j <= 2 * i; j++) {
System.out.print("*");
}
System.out.println();
}
for (int s = 0; s <= (n << 1) / 3; s++) {
for (int t = 0; t < 2 * n; t++) {
if ((t == 2 * n / 6 || t == 2 * n - (2 * n / 6)) && s < n/5) {
System.out.print("¥");
} else if (t >= 2 * n / 3 +1 && t <= 2 * n-(2 * n / 3 +1)) {
System.out.print("#");
} else {
System.out.print(" ");
}
}
System.out.println();
}
}}
到此这篇关于java实现双层圣诞树加修饰代码示例的文章就介绍到这了,更多相关java双层圣诞树内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!