用面向对象编程打印菱形 /** */ /** * PrintDiamondTest.java * 用面向对象编程打印菱形 * @author CodingMouse * @version 0.1 2008/5/11 * 开发/测试环境:jdk1.6 + eclipse SDK 3.3.2 */ public class PrintDiamondTest ... { public static void main(String[] args) ...{ PrintDiamondTest.printDiamond(10); } public static void printDiamond(int size) ...{ String result = ""; for(int column = 1 ; column <= size ; column++) ...{ int a = size - column; for(int s = 0 ; s < a ; s++) ...{ result += " "; } int b = 2 * column -1; for(int start = 0 ; start < b ; start++) ...{ result += "*"; } System.out.println(result); result = ""; } for(int n = 1 ; n <= size - 1 ; n++) ...{ //result += "a"; for(int c = 0 ; c < n ; c++) ...{ result += " "; } int numberOfStart = (2 * size -1) - 2 * n; for(int b = numberOfStart ; b > 0 ; b--) ...{ result += "*"; } System.out.println(result); result = ""; } }}