-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInteger_2.java
More file actions
36 lines (28 loc) · 919 Bytes
/
Copy pathInteger_2.java
File metadata and controls
36 lines (28 loc) · 919 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 HuaweiCoding;
import java.util.HashMap;
import java.util.Scanner;
/*
* 输入一个int型整数,按照从右向左的阅读顺序,返回一个不含重复数字的新的整数。
*/
public class Integer_2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
int nextInt = sc.nextInt();
String inputValue=nextInt+"";
StringBuilder sb=new StringBuilder(inputValue);
StringBuilder reverse = sb.reverse();
StringBuilder retsb=new StringBuilder();
HashMap<Character, Integer> hashMap=new HashMap<>();
for (Character value : reverse.toString().toCharArray()) {
if(hashMap.containsKey(value)) {
hashMap.put(value, hashMap.get(value)+1);
}else {
hashMap.put(value, 1);
retsb.append(value.toString());
}
}
System.out.println(retsb.toString());
}
}
}