计算整数各个位上的数字之和

package zzz;

import javax.swing.JOptionPane;


public class llyytt {

 
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int m1,m2,sum=0;
  String i=JOptionPane.showInputDialog(null,"Enter an number:n,0
  int intValue=Integer.parseInt(i);
  while(intValue!=0)
  {
   m1=intValue;
   sum=sum+m1;
   intValue=intValue/10;
  }
  
  JOptionPane.showMessageDialog(null,"The sum is " + sum,"梁燕婷",JOptionPane.INFORMATION_MESSAGE);
 }

}

posted on 2012-12-07 22:59  木本  阅读(258)  评论(0编辑  收藏  举报

导航