java双层圣诞树
海绵hong 人气:0A:有咋样的实力可以写出这个代码?
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(); } }}
加载全部内容