Skip to content

Instantly share code, notes, and snippets.

@Seolhun
Created May 10, 2018 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seolhun/94cf224689ccb0282a5d4dce0d0bb4e7 to your computer and use it in GitHub Desktop.
Save Seolhun/94cf224689ccb0282a5d4dce0d0bb4e7 to your computer and use it in GitHub Desktop.
java, reverse int without array
/**
* @author HunSeol
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ReverseInt {
static int T;
public static void main(String args[]) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] Q = bf.readLine().split(" ");
int a = Integer.parseInt(Q[0]);
int b = Integer.parseInt(Q[1]);
a = reverse(a);
b = reverse(b);
System.out.println(a);
System.out.println(b);
}
static int reverse(int value) {
int rev = 0;
while (value != 0) {
rev = (rev * 10) + (value % 10);
value = value / 10;
}
return rev;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment