用Java实现字母排列的三角形
public class HomeWork03 { public static void main(String[] args) { String str = "ABCDEFGHIJK"; for(int i=0; i<str.length(); i++){ for(int j=i; j<(i+8 > str.length() ? str.length() : i+8); j++){ System.out.print(str.substring(i, j+1)); System.out.println(); } System.out.println(); } } }
输出:
A AB ABC ABCD ABCDE ABCDEF ABCDEFG ABCDEFGH B BC BCD BCDE BCDEF BCDEFG BCDEFGH BCDEFGHI C CD CDE CDEF CDEFG CDEFGH CDEFGHI CDEFGHIJ D DE DEF DEFG DEFGH DEFGHI DEFGHIJ DEFGHIJK E EF EFG EFGH EFGHI EFGHIJ EFGHIJK F FG FGH FGHI FGHIJ FGHIJK G GH GHI GHIJ GHIJK H HI HIJ HIJK I IJ IJK J JK K