while循环打印*菱形
生活随笔
收集整理的這篇文章主要介紹了
while循环打印*菱形
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
效果圖如下圖所示:
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 }?
轉載于:https://www.cnblogs.com/ztt0918/p/7997690.html
總結
以上是生活随笔為你收集整理的while循环打印*菱形的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 多线程编程学习笔记——任务并行库(三)
- 下一篇: BZOJ 1085 [SCOI2005]