Created
May 10, 2018 07:27
-
-
Save Seolhun/94cf224689ccb0282a5d4dce0d0bb4e7 to your computer and use it in GitHub Desktop.
java, reverse int without array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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