1. 程式人生 > >while循環打印*菱形

while循環打印*菱形

col public pack pub color ++ file src 個數

效果圖如下圖所示:

技術分享圖片

 1 package myeclipseFiles2;
 2 
 3 public class Rhombus {
 4 
 5     public static void main(String[] args) {
 6         // TODO Auto-generated method stub
 7         int i=1;
 8         while(i<=4){
 9             int j=1;
10             //先打印出前i+1個數
11             while(j<=i+3){
12                 //
判斷打印的數中前幾個數應該是打印空格 13 if(j<=4-i){ 14 System.out.print(" "); 15 }else{ 16 System.out.print("*"); 17 } 18 j++; 19 } 20 System.out.println(); 21 i++; 22 }
23 int i1=1; 24 while(i1<=3){ 25 int j1=1; 26 while(j1<=7-i1){ 27 if(j1<=i1){ 28 System.out.print(" "); 29 }else{ 30 System.out.print("*"); 31 } 32 j1++;
33 } 34 System.out.println(); 35 i1++; 36 } 37 } 38 39 }

while循環打印*菱形