锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
渚嬪
0-->0
3-->3
000-->0
01010-->101
301100-->3011
00103-->103
1020.00-->1020
001.0100-->1.01
00.003-->0.003
鑻ュ瓧絎︿覆涓瓧絎?,E+-)鍒欎負闈炴硶瀛楃涓層?/p>
/**
* @param args
*/
static String removeFirst(String str) {
while (true) {
if (str.length() > 1) {
char c = str.charAt(0);
char nextC = str.charAt(1);
if (c != '0') {
break;
} else {
if (nextC == '.') {
break;
} else {
str = str.substring(1);
}
}
} else {
break;
}
}
return str;
}
static String removeLast(String str) {
while (true) {
if (str.length() > 1) {
char c = str.charAt(str.length() - 1);
char beforeC = str.charAt(str.length() - 2);
if (c != '0') {
break;
} else {
if (beforeC == '.') {
str = str.substring(0, str.length() - 2);
break;
} else {
str = str.substring(0, str.length() - 1);
}
}
} else {
break;
}
}
return str;
}
static boolean isCorrect(String str) {
return !str.contains("E") && !str.contains(",") && !str.contains("+")
&& !str.contains("-");
}
public static void main(String[] args) {
String str = "003E+3";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃(,E+-)!");
}
str = "0";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃,E+-!");
}
str = "3";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃,E+-!");
}
str = "000";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃,E+-!");
}
str = "01010";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃,E+-!");
}
str = "301100";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃,E+-!");
}
str = "00103";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃,E+-!");
}
str = "1020.00";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃,E+-!");
}
str = "001.0100";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃,E+-!");
}
str = "00.003";
if (isCorrect(str)) {
System.out.println(str + "-->" + removeLast(removeFirst(str)));
} else {
System.out.println("瀛楃涓蹭腑鍚湁闈炴硶瀛楃,E+-!");
}
}
}
]]>