package test1;
import java.util.Scanner;
public class Test6 {
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
System.out.println("请输入一个数字:");
String str = input.next();
int result = 0;
for( int i=0;i<str.length();i++ )
{
int a = Integer.parseInt(str.charAt(i)+"");
result+=a;
}
System.out.println( "您输入的数字是:"+str+",各位数字之和为:"+result );
}
}
温馨提示:内容为网友见解,仅供参考