import java.util.Scanner; public class Main { public static void main(String args[]){ String num; Scanner sc = new Scanner(System.in); while(sc.hasNext()){ num = sc.next(); int res = 0; int mid = (num.length()/2); StringBuilder sb = new StringBuilder(); for(int i=mid-1;i>=0;i--){ sb.append(num.charAt(i)); } if(num.length()%2==1){ res = Math.abs(Integer.parseInt(num.substring(mid+1))-Integer.parseInt(sb.toString())); }else{ res = Math.abs(Integer.parseInt(num.substring(mid))-Integer.parseInt(sb.toString())); } System.out.println(res); } sc.close(); } }
原文地址:http://blog.csdn.net/guorudi/article/details/42032559