列印三角形問題

2021-06-20 12:18:00 字數 781 閱讀 4810

列印如下所示等腰三角形

/* * 方法1

* f用來處理空格與*交替

* n為行數,k為*出現的數目

*/public static void outtri(int n) else

}system.out.println();

} }/* * 方法2

* f用來處理空格與*交替

* n為行數,k為*最大的位置

*/public static void outtri2(int n) else

}system.out.println();

} }}

列印如下圖所示空心三角形

思想如方法2,確定最遠的位置,然後比較輸出

package softtest;

public class trikongxin

public static void outtri(int n) else

} else else }}

system.out.println();

} }}

列印三角形

需求 之前咱們列印過正方形,也列印過乘法口訣,那今天來列印乙個三角形 正三角形,元素用 表示 bin bash 這個指令碼用來列印三角形 日期 2019 12 23 while true doread p please input the lenth n if z n then echo 要輸入乙個...

列印楊輝三角形

列印楊輝三角形 1000 ms 10000 kb 3016 15287 楊輝三角形具有如下特徵 1 每行數字左右對稱,由1開始逐漸變大,然後變小,回到1。2 第n行的數字個數為n個。3 第n行數字和為2 n 1 4 每個數字等於上一行的左右兩個數字之和。可用此性質寫出整個帕斯卡三角形。5 將第2n ...

列印楊輝三角形

列印楊輝三角形 楊輝三角形就是呈現金字塔型的結構 每個的數字表示式為 a n,x a n 1,x a n 1,x 1 結構如下 11,1 1,2,1 1,3,3,1 1,4,6,4,1 解題思路 迴圈列印的行數,由於對稱型每行的資料型別可以只計算一半,後面的一半完全對折過來。上 public sta...