public class Main {
public String solution(int n) {
String answer = "";
return answer;
}
public static void main(String[] args) {
Main method = new Main();
System.out.println(method.solution(718253));
}
}
해결법
방법 1
public class test01 {
public String solution(int n) {
String answer = "";
int sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
answer = Integer.toString(sum);
return answer;
}
public static void main(String[] args) {
test01 method = new test01();
System.out.println(method.solution(718253));
}
}