题意理解
这题只要你铁下心来用Java,那么就是随便写,注意一下取值范围,是有20位的,会爆int的精度,所以我用的是Long。
代码
import java.util.Scanner;
public class Main {
private static long reverseInt(String s) {
return Long.valueOf(new StringBuilder(s).reverse().toString());
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
if(string.endsWith("%")) {
String beforeReverse = string.substring(0, string.length() - 1);
System.out.println(reverseInt(beforeReverse) + "%");
} else if(string.contains("/")) {
String[] divides = string.split("/");
System.out.println(reverseInt(divides[0]) + "/" + reverseInt(divides[1]));
} else if(string.contains(".")) {
String[] nums = string.split("\\.");
String temp = reverseInt(nums[0]) + "." + reverseInt(nums[1]);
if(temp.endsWith(".0")) {
System.out.println(temp);
} else {
while(temp.endsWith("0")) {
temp = temp.substring(0, temp.length() - 1);
}
System.out.println(temp);
}
} else {
System.out.println(reverseInt(string));
}
scanner.close();
}
}