其中 1000的結果應爲 1! java
1. 採用常規方式,如123->321 其過程爲((3)*10+2)*10+1 code
private int reve(int x) { // TODO Auto-generated method stub int result = 0 ; int temp = x; while(temp > 0){ result = result * 10 + temp % 10; temp /= 10; } return result; }
private int reve(String x){ char[] chs = x.toCharArray(); int begin = 0; int end = chs.length - 1; while(begin < end){ if(chs[begin] != chs[end]){ char temp = chs[begin]; chs[begin] = chs[end]; chs[end] = temp; } ++begin; --end; } int result = Integer.parseInt(new String(chs)); return result; }