課程
/后端開發(fā)
/Java
/Java入門第一季(IDEA工具)升級(jí)版
能否用while語(yǔ)句打印*長(zhǎng)方形?
2015-09-17
源自:Java入門第一季(IDEA工具)升級(jí)版 4-14
正在回答
public class Rectangle {?? ?public static void main(String[] args) {?? ??? ?// 打印長(zhǎng)方形?? ??? ?// 第一種方法:for循環(huán)方法打印 打印8行,20列的長(zhǎng)方形?? ??? ?/*?? ??? ? * for(int i=1;i<=5;i++){//外層循環(huán)控制行數(shù) for(int?? ??? ? * j=1;j<=15;j++){//內(nèi)層循環(huán)控制每一行打印的數(shù)量,即列數(shù) System.out.print("*"); }?? ??? ? * System.out.println();//換行 }?? ??? ? */?? ??? ?// 第二種方法:while循環(huán)?? ??? ?int x = 1;?? ??? ?int y = 1;?? ??? ?while (x <= 5) {?? ??? ??? ?while (y <= 15) {?? ??? ??? ??? ?System.out.print("*");?? ??? ??? ??? ?y++;?? ??? ??? ?}?? ??? ??? ?System.out.println();?? ??? ??? ?y = 1;?? ??? ??? ?x++;?? ??? ?}?? ?}}
dumbaodouble
346746946 提問(wèn)者
可以的,while和for幾乎是可以互換的,只是for可以定義些臨時(shí)變量而已,
public static void main(String[] args) {
// TODO Auto-generated method stub
int i=0;
while(i < 3){
System.out.println("*********");
i++;
}
這樣算嗎,哈哈,反正看起來(lái)也是個(gè)長(zhǎng)方形
舉報(bào)
0基礎(chǔ)萌新入門第一課,從Java環(huán)境搭建、工具使用、基礎(chǔ)語(yǔ)法開始
2 回答用while語(yǔ)句怎樣打印三角形哪里錯(cuò)了
2 回答使用*打印長(zhǎng)方形是什么意思?
1 回答用for循環(huán)怎么打印不出長(zhǎng)方形?
1 回答打印長(zhǎng)方形 我的怎么么不一樣?
3 回答為什么這段代碼不能打印長(zhǎng)方形呢?請(qǐng)學(xué)長(zhǎng)們指教。。。
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-09-17
public class Rectangle {
?? ?public static void main(String[] args) {
?? ??? ?// 打印長(zhǎng)方形
?? ??? ?// 第一種方法:for循環(huán)方法打印 打印8行,20列的長(zhǎng)方形
?? ??? ?/*
?? ??? ? * for(int i=1;i<=5;i++){//外層循環(huán)控制行數(shù) for(int
?? ??? ? * j=1;j<=15;j++){//內(nèi)層循環(huán)控制每一行打印的數(shù)量,即列數(shù) System.out.print("*"); }
?? ??? ? * System.out.println();//換行 }
?? ??? ? */
?? ??? ?// 第二種方法:while循環(huán)
?? ??? ?int x = 1;
?? ??? ?int y = 1;
?? ??? ?while (x <= 5) {
?? ??? ??? ?while (y <= 15) {
?? ??? ??? ??? ?System.out.print("*");
?? ??? ??? ??? ?y++;
?? ??? ??? ?}
?? ??? ??? ?System.out.println();
?? ??? ??? ?y = 1;
?? ??? ??? ?x++;
?? ??? ?}
?? ?}
}
2015-09-18
可以的,while和for幾乎是可以互換的,只是for可以定義些臨時(shí)變量而已,
2015-09-17
public static void main(String[] args) {
// TODO Auto-generated method stub
int i=0;
while(i < 3){
System.out.println("*********");
i++;
}
這樣算嗎,哈哈,反正看起來(lái)也是個(gè)長(zhǎng)方形