课堂2数字输出

import java.util.Scanner;
//信1605-1 20163430 王铭宇
public class Number {

   public static void main(String args[]){

  Num N=new Num();
  System.out.println("请输入一个整数:");
  Scanner input=new Scanner(System.in);
     int num=input.nextInt();
  System.out.println(N.NumWeishu(num)+"位数");
}

}
class Num{

  public int NumWeishu(int a){
  int sum=0;
  int num1;
  int num2;
  int weishu;
  num1=a%10;
  num2=a/10;
  sum=sum+num1;
  weishu=1;
  System.out.print(num1+"\t");
  while(num2!=0)
  {
  num1=num2%10;
  num2=num2/10;
  sum=sum+num1;
  weishu=weishu+1;
  System.out.print(num1+"\t");

}

  System.out.println("求和"+sum);
  return weishu;

}
}

posted @ 2017-10-10 14:35  格式化。  阅读(121)  评论(0编辑  收藏  举报