📄 sentinel.txt
字号:
// Program to add a series of numbers entered by the user
// The adding ends when the user enters the number zero
import javax.swing.JOptionPane;
public class Sentinel
{
public static void addSeries()
{
final int SENTINEL = 0;
int latestNum;
int total = 0;
String numStr;
JOptionPane.showMessageDialog(null,
"Enter a series of numbers, zero to end: " );
numStr = JOptionPane.showInputDialog(
"First number? " );
// convert from String to int
latestNum = Integer.parseInt(numStr);
while (latestNum != SENTINEL)
{
total = total + latestNum;
numStr = JOptionPane.showInputDialog(
"Next number?");
latestNum = Integer.parseInt(numStr);
}
JOptionPane.showMessageDialog(null,
"Total is " + total);
}
public static void main(String[] args)
{
addSeries();
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -