生活随笔
收集整理的這篇文章主要介紹了
*PAT_B_1024_Java(20分)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
replace()通過用 newChar 字符替換字符串中出現(xiàn)的所有 oldChar 字符,并返回替換后的新字符串
| insert() | 從index開始插入某個字符串 |
import java
.io
.BufferedReader
;
import java
.io
.IOException
;
import java
.io
.InputStreamReader
;public class Main {public static void main(String
[] args
) throws IOException
{BufferedReader bf
= new BufferedReader(new InputStreamReader(System
.in
));String
[] str
= bf
.readLine().split("E");StringBuffer sb
= new StringBuffer("");int index
= Integer
.parseInt(str
[1]);String buf
= str
[0];char sign
= str
[0].charAt(0);if (index
< 0) {sb
.append("0.");for (int i
= 1; i
< Math
.abs(index
); i
++) {sb
.append("0");}sb
.append(buf
.replace("+", "").replace("-", "").replace(".", ""));if (sign
== '-')sb
.insert(0, sign
);} else if (index
> 0) {char[] code
= buf
.replace("+", "").replace("-", "").replace(".", "").toCharArray();for (int i
= 0; i
< code
.length
; i
++) {sb
.append(code
[i
]);index
--;}for (int i
= 0; i
< index
+ 1; i
++) {sb
.append(0);}if (sign
== '-')sb
.insert(0, sign
);if (sb
.length() + index
+ 1 < sb
.length()) {sb
.insert(sb
.length() + index
+ 1, '.');}} else {String
[] temp
= buf
.split("\\.");if (Integer
.parseInt(temp
[1]) == 0) {sb
.append(Integer
.parseInt(temp
[0]));} elsesb
.append(buf
.replace("+", ""));}System
.out
.println(sb
.toString().trim());}
}
總結
以上是生活随笔為你收集整理的*PAT_B_1024_Java(20分)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。