【2.6】Sum the digits in an interger
//相加整数各个位的值
import java.util.*;
public class DigitsSum {
public static void main(String [] args){
long startTime=System.currentTimeMillis();
int digit;
Scanner inputScanner=new Scanner(System.in);
System.out.println("Enter a number between 0 and 1000: ");
digit=inputScanner.nextInt();
int fir,sec,thi,fou;
fou=digit%10;
int fou1=digit/10;
thi=fou1%10;
int thi1=fou1/10;
sec=thi1%10;
int sec1=thi1/10;
fir=sec1%10;
System.out.println("The sum of the digits is "+(fir+sec+thi+fou));
long endTime=System.currentTimeMillis();
System.out.println("运行时间:"+(endTime-startTime)+"毫秒");
}
}