[Programmers] 문자열 내림차순으로 배치하기 - 연습문제

동민·2021년 3월 10일
import java.util.Arrays;

// 문자열 내림차순으로 배치하기 - 연습문제
public class StrSortDESC {

	public String solution(String s) {

		String answer = "";

		char arr[] = s.toCharArray(); // toCharArray() : String -> char[]
		
		Arrays.sort(arr);
		for (int i = arr.length - 1; i >= 0; i--) {
			answer += arr[i];
		}

		return answer;

	}

	public static void main(String[] args) {

		StrSortDESC s = new StrSortDESC();

		System.out.println(s.solution("Zbcdefg"));
		 
	}

}
char[] arr = str.toCharArray() : String -> char[]
String[] arr = str.split("") : String -> String[]
profile
BE Developer

0개의 댓글