java實現雙層聖誕樹加修飾代碼示例
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雙層聖誕樹內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!