https://www.acmicpc.net/problem/2231
package backjun.Dbruteforce;
import java.util.Scanner;
public class 분해합 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
int result = 0;
for(int i=1;i<n;i++){
String t = Integer.toString(i);
int tmp = i;
for(int j=0; j<t.length(); j++)
tmp += ((int)t.charAt(j) - '0');
if (tmp == n){
result = i;
break;
}
}
System.out.println(result);
}
}
for 문을 통해 입력 받는 수 이전 수 까지 검사하는 방식
검사하기 위해 우선 현재 수를 저장하고 현재 수를 String으로 바꾼 후 String의 각각의 자리의 숫자를 다시 int로 변경 후 그 값을 모두 더해준다.
점점 java 언어에 익숙해 지는 중