-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprblm1323.java
More file actions
32 lines (29 loc) · 965 Bytes
/
prblm1323.java
File metadata and controls
32 lines (29 loc) · 965 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
import java.util.*;
public class prblm1323 {
public static void main(String[] args) {
int num = 9669;
System.out.println(new prblm1323().maximum69Number2(num));
}
public int maximum69Number (int num) {
String number = Integer.toString(num);
List<Integer> list = new ArrayList<>();
StringBuilder str = new StringBuilder();
boolean isChanged = false;
for (char ch : number.toCharArray()) {
list.add(Character.getNumericValue(ch));
}
for (int i = 0; i < list.size(); i++) {
if (list.get(i) == 6 && !isChanged) {
str.append(9);
isChanged = true;
}
else{
str.append(list.get(i));
}
}
return Integer.parseInt(str.toString());
}
public int maximum69Number2(int num) {
return Integer.valueOf(String.valueOf(num).replaceFirst("6", "9"));
}
}