Problem:
Sum of Numbers

Write a program which reads an integer and prints sum of its digits.

Input

The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000.

The input ends with a line including single zero. Your program should not process for this terminal symbol.

Output

For each dataset, print the sum of digits in x.

Sample Input

123
55
1000
0

Sample Output

6
10
1

Solution in JAVA (judge verdict: Accepted)

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		ArrayList<String> moji = new ArrayList<String>();
		String mm = "10";
		while(!mm.equals("0")){
			mm = scan.nextLine();
			moji.add(mm);
//			System.out.println("scannning");
		}
//		System.out.println("finir");
		for(int i=0; i<moji.size()-1; i++){
			String henkan = moji.get(i);
			char[] ichimoji = henkan.toCharArray();
			long nagasa = henkan.length();
			long sum = 0;
			for(int ii=0; ii<nagasa; ii++){
					sum += Character.getNumericValue(ichimoji[ii]);
			}
			System.out.println(sum);
		}
	}
}