The idea of public class reverseinteger {/** is as follows * 1. first, convert the integer variable to the string * 2. convert the string to a char array, and then compare the positive and negative values of the input variables. if it is positive, reverse it directly * 4. if it is negative, extract the positive and negative numbers first, and then reverse the ****/Public int revint (int x) {string STR = integer. tostring (x); char [] CH = Str. tochararray (); char [] B = new char [CH. length]; If (x> = 0) {for (INT I = CH. length-1, j = 0; I> = 0; I --, J ++) {B [J] = CH [I] ;}} else {B [0] = CH [0]; for (INT I = CH. length-1, j = 1; I> 0; I --, J ++) {B [J] = CH [I] ;}} string S = string. valueof (B); int result = integer. parseint (s); return result;} public static void main (string [] ARGs) {// todo auto-generated method stub int x = 123; reverseinteger rI = new reverseinteger (); int num = Ri. revint (x); system. out. println (Num );}}
Integer value reversal