gpt4 book ai didi

java - 我使用解析正确吗?

转载 作者:行者123 更新时间:2023-12-01 14:40:43 25 4
gpt4 key购买 nike

据我所知,我做得对(但显然不是)我正在尝试将字符串更改为 double ,因为我无法从 JPane 获得 double 。它给了我一个对象未​​初始化错误。我该如何修复它?

import javax.swing.JOptionPane;

public class jwindows {
public static void main (String args[]) {

double a, b, c;
double sum = a + b + c;
double product = a * b * c ;
double avarge = a * b * c / 3;

String stringA = JOptionPane.showInputDialog
(null, "Please enter first number");
a = Double.parseDouble(stringA);

String stringB = JOptionPane.showInputDialog
(null, "Please enter second number: ");
b = Double.parseDouble(stringB);

String stringC = JOptionPane.showInputDialog
(null, "Please enter third number: ");
c = Double.parseDouble(stringC);

JOptionPane.showInternalMessageDialog
(null, "The sum of the 3 numbers is " + sum);

JOptionPane.showInternalMessageDialog
(null, "The avarge of the 3 numbers is " + avarge);

JOptionPane.showInternalMessageDialog
(null, "The sum of the 3 numbers is " + product);
}
}

最佳答案

double a, b, c;
double sum = a + b + c;
double product = a * b * c ;
double avarge = a * b * c / 3;

您刚刚定义了变量,但没有初始化它们。获取所有 a、b、c 值后将它们移至右下方。

还有一件事:将 showInternalMessageDialog 更改为 showMessageDialog,因为您根本没有父组件。

关于java - 我使用解析正确吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15988939/

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