-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
36 lines (31 loc) · 752 Bytes
/
Solution.java
File metadata and controls
36 lines (31 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package leetCode_7;
/**
* @author dimdark
* @date 2017-04-21
* @time 6:34 PM
*/
public class Solution {
public int reverse(int x) {
if(x==Integer.MIN_VALUE){
return 0;
}
boolean negative = (x<0)?true:false;
int y;
x = Math.abs(x);
try {
y = Integer.parseInt(new StringBuffer(String.valueOf(x)).reverse().toString());
} catch (NumberFormatException e) {
return 0;
}
if(negative){
y = -y;
}
return y;
}
public static void main(String[] args) {
int x = 100;
Solution solution = new Solution();
System.out.println(x);
System.out.println(solution.reverse(x));
}
}