프로그래머스(자바)

    문자열 정렬하기(2) - String클래스의 toCharArray()

    나의 풀이 import java.util.*; class Solution { public String solution(String my_string) { char[] c = my_string.toLowerCase().toCharArray(); Arrays.sort(c); return new String(c); } } ▶ String클래스의 toCharArray()를 이용하자. ▶ new String( arr )을 하는 경우 "char형 배열"을 "문자열"로 만들수 있다. 다른 사람의 풀이 import java.util.*; class Solution { public String solution(String my_string) { String answer = ""; String[] word = my_str..

    문자열 정렬하기(1) - replaceAll(), Stream(), mapToInt()

    나의 풀이 import java.util.*; class Solution { public int[] solution(String my_string) { my_string=my_string.replaceAll("[^0-9]", ""); int[] result = new int[my_string.length()]; for (int i = 0; i < my_string.length(); i++) { result[i] = my_string.charAt(i) - '0'; } Arrays.sort(result); return result; } } ▶ [^0-9]는 0~9의 숫자가 아닌 문자열을 의미한다. ▶ replaceAll(A, B) → 문자열 A를 문자열B로 바꾼다. ▶ replaceAll(A, "") → 문..

    직각삼각형 출력하기★ - 독특하게 풀 수도 있다. + 이중for문

    나의 풀이 - 이중for문 j를 감소시키는 방향으로 import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i=1; i1; j--){ System.out.print("*"); } System.out.println(); } } } 다른 사람의 풀이1 - 파이썬풀이와 유사-repeat(반복횟수) import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new..

    역삼각형 출력하기-★별찍기

    public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i=1; i