Skip to content

Commit aea3187

Browse files
authored
Create ReverseInteger2.java
1 parent 420c734 commit aea3187

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

algorithms/ReverseInteger2.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.zetcode;
2+
3+
public class ReverseInteger2 {
4+
5+
public static void main(String[] args) {
6+
7+
int val = 7320300;
8+
9+
var str = String.valueOf(val);
10+
11+
char[] data = str.toCharArray();
12+
char[] data2 = new char[data.length];
13+
14+
for (int i = 0; i < data.length; i++) {
15+
16+
data2[i] = data[data.length - i - 1];
17+
}
18+
19+
// remove possible leading zeros
20+
int j = 0;
21+
while (data2[j] == '0') {
22+
23+
data2[j] = ' ';
24+
j++;
25+
}
26+
27+
var str2 = new String(data2);
28+
System.out.println(str2.stripLeading());
29+
}
30+
}

0 commit comments

Comments
 (0)