古詩詞大全網 - 個性簽名 - 很緊急。Java面試問題

很緊急。Java面試問題

公共?班級?FormatAmt?{

公共?字符串?金額(int?美元?int?美分){

字符串?結果?=?"";

int?t美元?=?美元;

而(t_dollar?& gt=?0){

字符串?臨時工?=?String.valueOf(t_dollar?%?1000);

如果(t_dollar?& gt=?1000){

結果?=?"000".子串(temp.length())?+?臨時工?+?結果;

結果?=?","?+?結果;

}

否則{

結果?=?臨時工?+?結果;

結果?=?"$"?+?結果;

}

t美元?/=?1000;

如果(t_dollar?==?0){

打破;

}

}

結果?+=?美分?& gt?10"."?+?美分?:?".0"?+?美分;

回歸?結果;

}

公共?靜電?作廢?main(String[]?args)?{

System.out.println(新?FormatAmt()。金額(123456,?0));

System.out.println(新?FormatAmt()。金額(49734321,?9));

System.out.println(新?FormatAmt()。金額(0,?99));

System.out.println(新?FormatAmt()。金額(249,?30));

System.out.println(新?FormatAmt()。金額(1000,?1));

}

}