import java.io.*;
public class Shuma{
public static void main(String args[]) throws IOException
{
int n;
int s;
String str;
BufferedReader buf;
buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("input an integer:");
str=buf.readLine();
n=Integer.parseInt(str);
s=fun(n);
System.out.println(s);
}
public static int fun(int n)
{ int s;
if(n/10==0) return n;
else { s=0;
while(n!=0) {
s+=n%10;
n/=10;
}
}
if(s/10!=0) return fun(s);
return s;
}
}
不转化为字符串也可以呀!