ex2_6.java
来自「Introduction to java programming 一书中所有编程」· Java 代码 · 共 31 行
JAVA
31 行
import javax.swing.JOptionPane;/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author xiaolei */public class EX2_6 { public static void main(String[] args) { int num, sum = 0; num = Integer.parseInt(JOptionPane.showInputDialog("输入0-1000之间的整数:")); if((num < 0) || (num > 1000)){ JOptionPane.showMessageDialog(null, "错误的输入值:"+num); System.exit(0); } while(num != 0){ sum += num % 10; num = num / 10; } JOptionPane.showMessageDialog(null, "结果:"+sum); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?