首页 > 代码库 > 算投资

算投资

import javax.swing.JOptionPane;public class Investment {    public static void main(String[] args){        double value;        String input = JOptionPane.showInputDialog(null,"请输入投资金额:","对话框",JOptionPane.QUESTION_MESSAGE);        String input1 = JOptionPane.showInputDialog(null,"请输入年利率:","对话框",JOptionPane.QUESTION_MESSAGE);        String input2 = JOptionPane.showInputDialog(null,"请输入投资年数:","对话框",JOptionPane.QUESTION_MESSAGE);        double investmen = Double.parseDouble(input);        double rate = Double.parseDouble(input1);        double year = Double.parseDouble(input2);        value = investmen * (Math.pow((1 + rate / 100),(year)));        JOptionPane.showMessageDialog(null, value);    }}

读取投资金额,年利率和年数,输出未来投资金额

未来投资金额=投资金额*(1+年利率)年数*12

使用方法Math.pow(a,b)来计算a的b次幂