import java.io.*;
public class ssss
{
public static void main(String[] args)
{
String num=null;
System.out.println("请输入一个整数,回车结束");
try
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
while((num=br.readLine())!=null&&num.length()!=0)
{
sum(num);
System.out.println("请输入一个整数,回车结束");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void sum(String num)
{
int b=0;
for(int i=0;i
b+=Integer.parseInt(num.substring(i,i+1));
}
System.out.println("该整数各个位上数字之和为:"+b);
}
}
public class Sum
{
public int sum(int number)
{
int result = 0;
if(number < 0)
number = -number;
while(number > 0)
{
result += number%10;
number /= 10;
}
return result;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Sum a = new Sum();
System.out.println("请输入一个整数:");
System.out.println(a.sum(scan.nextInt()));
}
}
public class A {
public int sum(int number) {
String a = number + "";
int sum = 0;
int length = a.length();
String[] aArray = new String[length];
for (int i=0; i
}
for (int i = 0; i < length; i++) {
sum += Integer.parseInt(aArray[i]);
}
System.out.print("该整数各个位上数字之和为:");
return sum;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
A a = new A();
System.out.print("请输入一个整数:");
System.out.print(a.sum(scan.nextInt()));
}
}
public int sum(int number)
{
String s=String.valueOf(number);int su=0;
for(int i=0;i,s.length();su+=s.charAt(i)-48;)
return su;
}