欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java怎么輸出三角代碼 java輸入n輸出數(shù)字三角形

用Java編程打印出這樣一個(gè)直角三角形,怎么編。

public?static?void?printTriangle(int?end)?{

成都創(chuàng)新互聯(lián)公司2013年至今,先為劍閣等服務(wù)建站,劍閣等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢(xún)服務(wù)。為劍閣企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

//?打印第一行

for?(int?i?=?0;?i??end?+?1;?i++)?{

System.out.print("*");

}

//?打印剩下的所有行

for?(int?i?=?1;?i??end?+?1;?i++)?{

System.out.println();//?打印一個(gè)換行

基段磨???????int?front?=?i;//?斜邊之前

int?behind?=?end;//?最后一個(gè)

//?front即斜邊之前都打印空格

for?(int?k?=?0;?k??front;?k++)?{

System.out.print("?");

}

//?最后一行只打印燃攜一個(gè)*號(hào)

if?(i??end)?{

搏斗System.out.print("*");

}

//?斜邊到最后之間打印空格

for?(int?k?=?front?+?1;?k??behind;?k++)?{

//?第一行倒數(shù)第三列打印直角標(biāo)志

if?(i?==?1)?{

if?(k?==?behind?-?2)?{

System.out.print("*");

}?else?{

System.out.print("?");

}

}

//?第二行倒數(shù)第三列、倒數(shù)第二列打印直角標(biāo)識(shí)

else?if?(i?==?2)?{

//?倒數(shù)

if?(k?==?behind?-?2?||?k?==?behind?-?1)?{

System.out.print("*");

}?else?{

System.out.print("?");

}

}?else?{

System.out.print("?");

}

}

//?打印最后一個(gè)*號(hào)

System.out.print("*");

}

}

你也可以用數(shù)組來(lái)打印

下面是打印出來(lái)的圖案

用java程序?qū)崿F(xiàn)三角形的輸出,要求如下

class NoParamException extends Exception{

public NoParamException(String message)

{super(message);}

}

class InputDecimalException extends Exception{}

public class HOMEWORK

{

public static float getHeight(String args[])throws NoParamException,InputDecimalException

{

float m;

if(args.length==0)

throw new NoParamException("NoParamException occures!");

m=Float.parseFloat(args[0]);

if((int)m!=m)throw new InputDecimalException();

return m;

}

public static void main(String args[])

{

float H=0;

try{

H=getHeight(args);

}

catch(NoParamException e){

System.out.println("NoParamException occures,please input again!");

}

catch(InputDecimalException e){

System.out.println("InputDecimalException occures,please input again!"仔閉);

}

catch(Exception e){

System.out.println("NoParamException occures,please input again!");

}

for(int i=1;i=H;i++)

? ? {

? ? ? ? for(int j=0;jH-i;j++)

? ? ? ? System.out.print(" ");

? ?念做裂 ? for(int k=0;k2*i-1;k++)

? ? ? ? ? System.out.print("*");

? ? ?胡盯 System.out.print("\n");

? ? }

}

}

可以進(jìn)行兩種異常控制,一種是無(wú)參數(shù)異常,一種是輸入小數(shù)的異常

這是運(yùn)行過(guò)程,記得程序中的publi class名字改過(guò)來(lái),與文件名一樣

名稱(chēng)欄目:java怎么輸出三角代碼 java輸入n輸出數(shù)字三角形
文章起源:http://chinadenli.net/article44/dspghee.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)自適應(yīng)網(wǎng)站手機(jī)網(wǎng)站建設(shè)動(dòng)態(tài)網(wǎng)站外貿(mào)建站網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)