package 上機練習; import java.util.Scanner; public class A06 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner (System.in); System.out.println("請輸入菱形的行數:"); int rows = input.nextInt(); while(rows%2==0){ System.out.println("請輸入奇數:"); rows = input.nextInt(); } int n=(rows+1)/2; for (int i = 1; i <=n; i++) { for (int j = 1; j <=n-i; j++) { System.out.print(" "); } for (int k = 1; k <=2*i-1; k++) { System.out.print("*"); } System.out.println(); } for (int i =n-1; i>0; i--) { for (int n1 = i; n1 <rows-i; n1++) { System.out.print(" "); } for (int j = 1; j <=2*i-1; j++) { System.out.print("*"); } System.out.print("\n"); } } }