标签:out stat util oid lan string scanner text 大于
import java.util.*;
public class Number2 {
public void run(int number){
if(number > 1000){
System.out.println("输入数字大于1000!");
System.exit(0);
}
int [] a= new int[3];
a[2] = number /100;
a[1] = (number - a[2]*100)/10;
a[0] = (number - a[2]*100 - a[1]*10)/1;
int total = 0;
total = a[0] + a[1] + a[2];
System.out.println("你输入的数字是:" + number + " 它的各位数之和是:" + total);
}
public static void main(String args[])
{
Number2 num = new Number2();
System.out.println("请输入一个1000以内的数");
Scanner reader=new Scanner(System.in);
int number = reader.nextInt();
num.run(number);
}
}
标签:out stat util oid lan string scanner text 大于
原文地址:http://www.cnblogs.com/zhuli-1/p/7542373.html