finderrors.java
来自「《A first book of java》by Gary J.Bronson 」· Java 代码 · 共 32 行
JAVA
32 行
import javax.swing.*;
import java.text.*; // needed for formatting
public class FindErrors
{
public static void main(String[] args)
{
String s1, outMessage;
double capital, amount, rate, nyrs;
DecimalFormat num = new DecimalFormat(",###.00");
outMessage = "This program calculates the amount of money\n"
+ "in a bank account for an initial deposit\n"
+ "invested for n years at an interest rate r.";
JOptionPane.showMessageDialog(null, outMessage,
"Program 4.7",
JOptionPane.INFORMATION_MESSAGE);
s1 = JOptionPane.showInputDialog("Enter the initial amount in the account:");
amount = Double.parseDouble(s1);
s1 = JOptionPane.showInputDialog("Enter the number of years:");
nyrs = Double.parseDouble(s1);
capital = amount * Math.pow((1 + rate/100.0), nyrs);
outMessage = "The final amount of money is $" +num.format(capital);
JOptionPane.showMessageDialog(null, outMessage,
"Program 4-7",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?