ACM (TJU) : 1551


//package volume_VI;

import java.util.Scanner;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {

Scanner input = new Scanner (System.in);

String s = input.next();

while ( ! s.equals(“0”) ) {

int sum = 0;

for ( int i = 0; i < s.length(); i++ ) sum += (s.charAt(i) - 48); if ( sum / 10 == 0 ) System.out.println (sum); else { int root = sum; while ( root / 10 != 0 ) { sum = 0; while ( root != 0 ) { sum += root % 10; root /= 10; } root = sum; } System.out.println (sum); } s = input.next(); } } } [/sourcecode]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s