반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 금융IT
- 알고리즘
- 언더라이터
- 백준 알고리즘
- 익명클래스
- 익명객체
- 멀티스레드
- 모바일
- 안드로이드
- 너비탐색
- 데이터베이스
- CKLU
- 다이나믹 프로그래밍
- IT
- 조합
- dfs
- dp
- BFS
- 삼성sw문제
- backjoon
- 개발
- 현대오토에버 코딩테스트
- 네트워크
- 프로그래머스
- Android
- 백준
- 재귀함수
- 자바
- 삼성SW테스트
- Java
Archives
- Today
- Total
Limky 삽질블로그
[Algorithm] 정수 내림차순으로 배치하기 본문
반응형
Programmers Level_02
정수 내림차순으로 배치하기
reverseInt 메소드는 int형 n을 매개변수로 입력받습니다.
n에 나타나는 숫자를 큰것부터 작은 순으로 정렬한 새로운 정수를 리턴해주세요.
예를들어 n이 118372면 873211을 리턴하면 됩니다.
n은 양의 정수입니다.
package Programmers_Level02;
import java.util.Arrays;
public class ReverseInt {
public static void main(String[] args) {
// TODO Auto-generated method stub
ReverseInt ri = new ReverseInt();
System.out.println(ri.reverseInt(118372));
}
public int reverseInt(int n){
String str = Integer.toString(n);
Integer[] array = new Integer[str.length()];
for(int i=0; i<array.length; i++){
array[i] = Character.getNumericValue(str.charAt(i));
}
Arrays.sort(array);
String result = "";
for(int i = array.length-1; i >=0; i--){
result += Integer.toString(array[i]);
}
return Integer.parseInt(result);
}
}
반응형
'Algorithm > Programmers' 카테고리의 다른 글
| [Algorithm] 점프뛰기 (JumpCase) (0) | 2017.10.05 |
|---|---|
| [Algorithm] 시저암호 (Caesar) (0) | 2017.10.05 |
| [Algorithm] 행렬의 곱셈 (ProductMatrix) (0) | 2017.10.04 |
| [Algorithm] 소수 찾기 (NumberOfPrime ) (0) | 2017.10.04 |
| [Algorithm] 하샤드(Harshad) 수 (0) | 2017.10.04 |