gpt4 book ai didi

java - 类预期错误。需要简单程序的帮助

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

当我运行这个程序时,我收到以下错误:

Testscore.java:26: class expected
grade = double.parseDouble(strInput);
^
Testscore.java:26: ';' expected
grade = double.parseDouble(strInput);
^
Testscore.java:26: not a statement
grade = double.parseDouble(strInput);
^
Testscore.java:26: ';' expected
grade = double.parseDouble(strInput);
^
4 errors

我的double.parseDouble(strInput);正确吗?

import javax.swing.*;
import java.lang.IllegalArgumentException;

public class Testscore
{
public static void main(String[] args)
{
int numberofTests = 0;

double grade = new double[numberofTests];

double startgrade = 0;

String strInput;

// Get how many tests are used

strInput = JOptionPane.showInputDialog(null, "How many tests do you have? ");
numberofTests = Integer.parseInt(strInput);

grade = new double[(int) numberofTests];

for (int index = 0; index < grade.length; index++)
{
strInput = JOptionPane.showInputDialog(null, "Enter Test Score." + (index + 1));
grade = double.parseDouble(strInput);

if (grade[index] < 0|| grade[index] > 100 )
{
try
{
throw new InvalidTestScore();
}

catch (InvalidTestScore e)
{
e.printlnStackTrace();
}
}
}

for (int index = 0; index < grade.length; index++ )

{
startgrade += grade[index];
}

average = startgrade/grade.length;

System.out.print("The average is: " + average);

}
}

最佳答案

它是Double,大写D

请注意 doubleDouble 之间的区别。 “小” double 型是原始类型。另一个是类 - java.lang.Double。您可以在类上调用诸如 parseDouble(..) 之类的方法,而不是基元上的方法。 “big” double 也称为“包装类”,因为它将原始类型包装到一个类中。

关于java - 类预期错误。需要简单程序的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4880141/

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