ゞ沉默是金ゞ
魚離不開水,但是沒有說不離開哪滴水.
BlogJava
首頁
新隨筆
新文章
聯(lián)系
聚合
管理
posts - 98,comments - 104,trackbacks - 0
<
2009年6月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
常用鏈接
我的隨筆
我的文章
我的評論
我的參與
最新評論
留言簿
(3)
給我留言
查看公開留言
查看私人留言
隨筆分類
Ant
Broker(1)
DB(8)
EJB(2)
eXtreme(7)
Hibernate
HTTP(6)
Java EE(8)
Java SE(31)
Jrules
Maven
Spring
Spring基礎(chǔ)(1)
Struts
webservice(2)
其他收集(6)
性能測試(1)
搜索引擎
面試相關(guān)
隨筆檔案
2012年12月 (1)
2012年11月 (1)
2012年8月 (16)
2012年7月 (6)
2012年6月 (11)
2011年3月 (1)
2010年12月 (1)
2010年11月 (2)
2010年8月 (1)
2010年7月 (3)
2010年5月 (1)
2010年1月 (1)
2009年12月 (3)
2009年11月 (2)
2009年8月 (1)
2009年6月 (4)
2009年5月 (1)
2009年4月 (1)
2009年3月 (6)
2009年2月 (3)
2008年12月 (4)
文章分類
EJB(1)
代碼收集
實用腳本
文章檔案
2012年6月 (2)
2012年1月 (1)
2011年8月 (1)
2009年11月 (1)
2009年3月 (1)
2009年2月 (2)
搜索
最新評論
1.?re: How to Create Client/Server Keystores using Java Keytool
Shawn?
--Freud
2.?re: HTTP/1.1 Cache-Control的理解
這是網(wǎng)頁代碼,還是IIS 代碼
--marmoglass
3.?re: How To Avoid javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Problem Using Apache HttpClient
評論內(nèi)容較長,點擊標題查看
--dashi99
4.?re: How To Avoid javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Problem Using Apache HttpClient
評論內(nèi)容較長,點擊標題查看
--shigangxing
5.?re: Part 12: java.util.concurrent : SingleThreadPool Example
評論內(nèi)容較長,點擊標題查看
--NotNolyJava
閱讀排行榜
1.?HTTP/1.1 Cache-Control的理解(10102)
2.?MYSQL 連接數(shù)據(jù)庫命令收藏(8622)
3.?什么是RFC?(6618)
4.?can not be represented as java.sql.Timestamp(5955)
5.?How To Avoid javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated Problem Using Apache HttpClient(3649)
評論排行榜
1.?Java應(yīng)用基礎(chǔ):網(wǎng)友精選25個Java試題分享(18)
2.?踏實與成功(11)
3.?Eclipse中10個比較有用的快捷鍵組合(轉(zhuǎn))(7)
4.?摘:一個Java程序員應(yīng)該掌握的10項技能(6)
5.?Java獲取客戶端真實IP地址的兩種方法(5)
用 * 打印出各種圖形
先看效果:
代碼:
public
class
PrintTriangle
{
public
static
void
main(String[] args)
{
System.out.println(
"
======左邊正三角形======
"
);
printTopLeft(
5
);
System.out.println(
"
======左邊倒三角形======
"
);
printDownLeft(
5
);
System.out.println(
"
======打印右正三角形======
"
);
printTopRight(
5
);
System.out.println(
"
======打印右倒三角形======
"
);
printDownRight(
5
);
System.out.println(
"
======打印正中三角形======
"
);
printTopCenter(
5
);
System.out.println(
"
======打印倒中三角形======
"
);
printDownCenter(
5
);
System.out.println(
"
======打印中正空三角形======
"
);
printTopMidBlank(
5
);
System.out.println(
"
======打印中倒空三角形======
"
);
printDownMidBlank(
5
);
System.out.println(
"
======打印正人字狀======
"
);
printTopRen(
5
);
}
/**/
/*
* 打印正人字狀
*/
public
static
void
printTopRen(
int
n)
{
for
(
int
i
=
1
; i
<=
n; i
++
)
{
for
(
int
j
=
i; j
<
n; j
++
)
{
System.out.print(
"
"
);
}
//
左半部分
for
(
int
j
=
1
; j
<=
i; j
++
)
{
if
(j
==
1
)
System.out.print(
"
*
"
);
else
System.out.print(
"
"
);
}
//
右半部分
for
(
int
j
=
1
; j
<
i; j
++
)
{
if
(j
==
i
-
1
)
System.out.print(
"
*
"
);
else
System.out.print(
"
"
);
}
System.out.println();
}
}
/**/
/*
* 打印倒空三角形
*/
public
static
void
printDownMidBlank(
int
n)
{
for
(
int
i
=
1
; i
<=
n; i
++
)
{
for
(
int
j
=
1
; j
<
i; j
++
)
{
System.out.print(
"
"
);
}
for
(
int
j
=
i; j
<=
n; j
++
)
{
if
(i
==
1
||
j
==
i
||
i
==
n)
System.out.print(
"
*
"
);
else
System.out.print(
"
"
);
}
for
(
int
j
=
i; j
<
n; j
++
)
{
if
(i
==
1
||
j
==
n
-
1
)
System.out.print(
"
*
"
);
else
System.out.print(
"
"
);
}
System.out.println();
}
}
/**/
/*
* 打印中正空三角形
*/
public
static
void
printTopMidBlank(
int
n)
{
for
(
int
i
=
1
; i
<=
n; i
++
)
{
for
(
int
j
=
i; j
<
n; j
++
)
{
System.out.print(
"
"
);
}
//
左半部分
for
(
int
j
=
1
; j
<=
i; j
++
)
{
if
(j
==
1
||
i
==
n)
System.out.print(
"
*
"
);
else
System.out.print(
"
"
);
}
//
右半部分
for
(
int
j
=
1
; j
<
i; j
++
)
{
if
(j
==
i
-
1
||
i
==
n)
System.out.print(
"
*
"
);
else
System.out.print(
"
"
);
}
System.out.println();
}
}
/**/
/*
* 打印倒中三角形
*/
public
static
void
printDownCenter(
int
n)
{
for
(
int
i
=
1
; i
<=
n; i
++
)
{
for
(
int
j
=
1
; j
<
i; j
++
)
{
System.out.print(
"
"
);
}
for
(
int
j
=
i; j
<=
n; j
++
)
{
System.out.print(
"
*
"
);
}
for
(
int
j
=
i; j
<
n; j
++
)
{
System.out.print(
"
*
"
);
}
System.out.println();
}
}
/**/
/*
* 打印正中三角形
*/
public
static
void
printTopCenter(
int
n)
{
for
(
int
i
=
1
; i
<=
n; i
++
)
{
for
(
int
j
=
i; j
<
n; j
++
)
{
System.out.print(
"
"
);
}
//
左半部分
for
(
int
j
=
1
; j
<=
i; j
++
)
{
System.out.print(
"
*
"
);
}
//
右半部分
for
(
int
j
=
1
; j
<
i; j
++
)
{
System.out.print(
"
*
"
);
}
System.out.println();
}
}
/**/
/*
* 打印右倒三角形
*/
public
static
void
printDownRight(
int
n)
{
for
(
int
i
=
n; i
>=
1
; i
--
)
{
for
(
int
j
=
n; j
>
i; j
--
)
{
System.out.print(
"
"
);
}
for
(
int
j
=
i; j
>=
1
; j
--
)
{
System.out.print(
"
*
"
);
}
System.out.println();
}
}
/**/
/*
* 打印右正三角形
*/
public
static
void
printTopRight(
int
n)
{
for
(
int
i
=
1
; i
<=
n; i
++
)
{
for
(
int
j
=
n; j
>
i; j
--
)
{
System.out.print(
"
"
);
}
for
(
int
j
=
i; j
>=
1
; j
--
)
{
System.out.print(
"
*
"
);
}
System.out.println();
}
}
/**/
/*
* 打印左正三角型
*/
public
static
void
printTopLeft(
int
n)
{
for
(
int
i
=
1
; i
<=
n; i
++
)
{
for
(
int
j
=
1
; j
<=
i; j
++
)
{
System.out.print(
"
*
"
);
}
System.out.println();
}
}
/**/
/*
* 打印左倒三角形
*/
public
static
void
printDownLeft(
int
n)
{
for
(
int
i
=
1
; i
<=
n; i
++
)
{
for
(
int
j
=
n; j
>=
i; j
--
)
{
System.out.print(
"
*
"
);
}
System.out.println();
}
}
}
希望大家多提意見。
posted on 2009-06-02 14:43
ゞ沉默是金ゞ
閱讀(1409)
評論(2)
編輯
收藏
所屬分類:
Java SE
FeedBack:
#
re: 用 * 打印出各種圖形
2009-06-02 15:03 |
FEJAY
學(xué)習(xí)了
回復(fù)
更多評論
#
re: 用 * 打印出各種圖形
2009-06-03 17:14 |
thebye85
看得我都是星星
回復(fù)
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關(guān)文章:
jvm學(xué)習(xí)筆記
ThreadPoolExecutor usage summary
Part 13: java.util.concurrent - Atomic Variables
Part 12: java.util.concurrent : SingleThreadPool Example
Part 11: java.util.concurrent - CachedThreadPool Example
Part 10: java.util.concurrent - ScheduledThreadPool Example
Part 9: java.util.concurrent : FixedThreadPool Example
Part 8: java.util.concurrent - "Executors" Factory Threads Pool
Part 7: java.util.concurrent - invokeAll via ExecutorService
Part 6: java.util.concurrent - Lock and Condition Object
Copyright ©2025 ゞ沉默是金ゞ Powered By
博客園
模板提供:
滬江博客
主站蜘蛛池模板:
县级市
|
岑巩县
|
延津县
|
阳新县
|
获嘉县
|
襄汾县
|
肥城市
|
湘阴县
|
扬州市
|
体育
|
那曲县
|
乌拉特中旗
|
佛山市
|
民勤县
|
桃园市
|
曲松县
|
思南县
|
曲靖市
|
宿迁市
|
拉萨市
|
仁化县
|
尉犁县
|
敦煌市
|
永修县
|
三门峡市
|
晋州市
|
清水县
|
通辽市
|
三亚市
|
寿阳县
|
洪雅县
|
哈尔滨市
|
道真
|
漠河县
|
大余县
|
新蔡县
|
新源县
|
宜川县
|
潼关县
|
桐梓县
|
兴业县
|