问题及代码:
import javax.swing.JOptionPane;
public class first {
public static void main(String[] args) {
String s=JOptionPane.showInputDialog("请输入一个0—1000的数:");
double a=Double.parseDouble(s);
if(a>=0&&a<=1000)
{
int b=(int)a/100;
int c=(int)a/10-b*10;
int d=(int)a%10;
JOptionPane.showMessageDialog(null, b+c+d, "Summing the digits in an integer" , JOptionPane.INFORMATION_MESSAGE);
}
}
}
运行结果: