티스토리 뷰

DESCRIPTION

정수 N (0~1,000)를 표현하는 각 자리의 숫자들의 합계를 구하는 프로그램을 작성하세요. 예를 들어 932 정수의 각 자리 숫자들의 합계는 9+3+2=14 입니다. 

Write a program that reads an integer N between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14. 

INPUT

* Line 1 : 단일 정수 N (0~1,000)

 

OUTPUT

* Line 1 : 단일 정수 (각 자리의 숫자를 더한 값)

 

SAMPLE INPUT
932
SAMPLE OUTPUT
14
HINT

Use the % operator to extract digits, and use the / operator to remove the extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93.


'학교공부 > JAVA' 카테고리의 다른 글

[JAVA] 기하: 삼각형의 넓이  (0) 2017.07.26
[JAVA] 건강: BMI 계산  (0) 2017.07.26
[JAVA] 미터를 피트와 인치로  (0) 2017.07.26
[JAVA] 원통의 부피  (0) 2017.07.26
[JAVA] 시간, 분, 초  (0) 2017.07.26
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2025/06   »
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
글 보관함