📄 addnumbers.java
字号:
import javax.swing.*;
public class AddNumbers
{
public static void main(String[] args)
{
String s1, outMessage;
final int MAXNUMS = 4;
int count;
double num, total;
outMessage = "This program will ask you to enter "
+ MAXNUMS + " numbers.";
JOptionPane.showMessageDialog(null, outMessage, "Program 5.6",
JOptionPane.INFORMATION_MESSAGE);
count = 1;
total = 0;
while (count <= MAXNUMS)
{
s1 = JOptionPane.showInputDialog("Enter number " + count + ":");
num = Double.parseDouble(s1);
total = total + num;
JOptionPane.showMessageDialog(null, "The total is now "+ total,
"Program 5-6",
JOptionPane.INFORMATION_MESSAGE);
count++;
}
JOptionPane.showMessageDialog(null, "The final total is " + total,
"Program 5_6",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -