满意答案
joykwok
2016.04.18
采纳率:56% 等级:9
已帮助:569人
package rnd;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class getNum {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println(get(Long.parseLong(br.readLine())));
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static long get(Long num) {
String s = String.valueOf(num);
byte[] by = s.getBytes();
byte[] by2 = new byte[by.length];
int t = by.length - 1;
for (int i = 0; i <= by.length - 1; i++) {
by2[t] = by[i];
t--;
}
return Long.parseLong(new String(by2));
}
// 这个是在网上找到的方法,不过缺陷是要确定位数。
public static long get2(Long num) {
String s = String.valueOf(num);
String s2;
System.out.print("请输入你想逆转的数字");
Scanner input = new Scanner(System.in);
s2 = s.replaceAll("([0-9])([0-9])([0-9])([0-9])([0-9])", "$5$4$3$2$1");
return Long.parseLong(new String(s2));
}
}
00分享举报