gpt4 book ai didi

java - 在 inputStr 上找不到符号

转载 作者:行者123 更新时间:2023-12-01 22:21:05 26 4
gpt4 key购买 nike

import javax.swing.JOptionPane;

public class TestScores
{
public static void main(String[] args)
{
double testscore1, testscore2, testscore3, testscore4;
double weigh1, weigh2, weigh3, weigh4;

String testscore1Str, testscore2Str, testscore3Str, testscore4Str;

testscore1Str =
JOptionPane.showInputDialog("Enter first score: ");
testscore1 = Double.parseDouble(testscore1Str);

testscore2Str =
JOptionPane.showInputDialog("Enter second score: ");
testscore2 = Double.parseDouble(testscore2Str);

testscore3Str =
JOptionPane.showInputDialog("Enter third score: ");
testscore3 = Double.parseDouble(testscore3Str);

testscore4Str =
JOptionPane.showInputDialog("Enter fourth score: ");
testscore4 = Double.parseDouble(testscore4Str);

weigh1 = testscore1 * 0.20;
weigh2 = testscore2 * 0.35;
weigh3 = testscore2 * 0.15;
weigh4 = testscore2 * 0.30;

outputStr = "testscore1: " + weigh1 + "/n" +
"testscore2: " + weigh2 + "/n" +
"testscore3: " + weigh3 + "/n" +
"testscore4: " + weigh4 + "/n";

JOptionPane.showMessageDialog(null, outputStr, "TestScores",
JOptionPane.INFORMATION_MESSAGE);

System.exit(0);
}

}

我在“outputStr”上遇到找不到符号错误。

通常这只是一个简单的拼写错误,但我不知道问题出在哪里。任何指向正确方向的指示将不胜感激。

谢谢!

最佳答案

在这一行中:

outputStr = "testscore1: " + weigh1 + "/n" +
"testscore2: " + weigh2 + "/n" +
"testscore3: " + weigh3 + "/n" +
"testscore4: " + weigh4 + "/n";

您无法初始化outputStr。试试这个:

String outputStr = "testscore1: " + weigh1 + "/n" +
"testscore2: " + weigh2 + "/n" +
"testscore3: " + weigh3 + "/n" +
"testscore4: " + weigh4 + "/n";

以后,在 Stack Overflow 上提问之前,请尝试进行一些基本的调试。查看How to Debug Small Programs作者:埃里克·利珀特。另外,写一个Minimal, Complete, and Verifiable example确实有助于识别错误。

IDE 还会在您创建此类错误时明确指出这些错误。 NetBeansIntelliJ IDEA是两个很好的 Java IDE。

关于java - 在 inputStr 上找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764140/

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