在inputStr上找不到符号

时间:2015-04-21 06:03:47

标签: java

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"上找到符号错误。

通常它只是一个简单的拼写错误,但我无法弄清问题是什么。任何指向正确方向的指针都将非常感激。

谢谢!

1 个答案:

答案 0 :(得分:3)

在这一行:

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之前,请尝试进行一些基本的调试。查看Eric Lippert的How to Debug Small Programs。另外,编写Minimal, Complete, and Verifiable example确实有助于识别错误。

IDE也会在您制作错误时明确指出这样的错误。 NetBeansIntelliJ IDEA是两个不错的Java IDE。