gpt4 book ai didi

java - JOptionPane 无法显示所有内容

转载 作者:行者123 更新时间:2023-12-02 05:35:27 26 4
gpt4 key购买 nike

您好,SO 社区,我最近将程序从扫描仪输入和显示更改为 JOptionPane 输入和显示,它被设置为显示用户指定年份的投资

目前,如果年数超过 3,它将终止程序,我将如何解决这个问题和/或创建一个弹出窗口来显示结果?先谢谢大家了。

import java.util.*;
import javax.swing.JOptionPane;

public class Investing {

public static void main (String[] args){

double amount;

double principal;

double rate;

Scanner input1 = new Scanner(System.in);

String principals = JOptionPane.showInputDialog("Please Enter The Principal");
principal = Double.parseDouble(principals);

String rates = JOptionPane.showInputDialog("Please Enter The Rate Of Interest");
rate = Double.parseDouble(rates);

String years = JOptionPane.showInputDialog("Please Enter The Number Of Investment Years");
double g = Double.parseDouble(years);
String zs = JOptionPane.showInputDialog( "Please Enter Annual Contribution");
double z = Double.parseDouble(zs);

amount = principal;
for(int year = 1; year <= g; year++){
amount *= 1 + rate/100;
amount+= z;
JOptionPane.showMessageDialog( null, year + " " + amount, zs, year);
}
}
}

最佳答案

您错误地使用了 JOptionPane

JOptionPane.showMessageDialog( null, year + "  " + amount, zs, year);

您将年份作为消息类型传递,因此在第 3 年之后失败。您应该这样做

JOptionPane.showMessageDialog( null, year + "  " + amount, "title", JOptionPane.INFORMATION_MESSAGE );

关于java - JOptionPane 无法显示所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25001200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com