Skip to content

Commit b9df41f

Browse files
author
holmir97
committed
한 디짓만 변경하여 최대값 찾기
1 parent 298cd69 commit b9df41f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Max69Num.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
public class Max69Num {
3+
public static void main(String[] args) {
4+
System.out.println(maximum69Number(9699));
5+
}
6+
public static int maximum69Number (int num) {
7+
String tmp="";
8+
String strNum = Integer.toString(num);
9+
String[] arrStrNum = strNum.split("");
10+
11+
for(int i = 0; i<arrStrNum.length; i++){
12+
if(arrStrNum[i].equals("6")){
13+
arrStrNum[i] = "9";
14+
break;
15+
}
16+
}
17+
for(int i =0 ;i<arrStrNum.length;i++)
18+
tmp = tmp.concat(arrStrNum[i]);
19+
20+
strNum = tmp;
21+
num = Integer.parseInt(strNum);
22+
return num;
23+
}
24+
}

0 commit comments

Comments
 (0)