Java 类预期错误。需要简单程序的帮助吗
运行此程序时,会出现以下错误:Java 类预期错误。需要简单程序的帮助吗,java,loops,Java,Loops,运行此程序时,会出现以下错误: Testscore.java:26: class expected grade = double.parseDouble(strInput); ^ Testscore.java:26: ';' expected grade = double.parseDouble(strInput); ^ Tes
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);
}
}
import javax.swing.*;
导入java.lang.IllegalArgumentException;
公共类测试分数
{
公共静态void main(字符串[]args)
{
int numberofTests=0;
双级=新的双级[测试次数];
双星级=0;
弦纹;
//获取使用了多少个测试
strInput=JOptionPane.showInputDialog(null,“您有多少个测试?”);
numberofTests=Integer.parseInt(strInput);
等级=新的双[(int)个测试];
对于(int index=0;index100)
{
尝试
{
抛出新的InvalidTestScore();
}
捕获(无效测试分数e)
{
e、 printlnStackTrace();
}
}
}
对于(int index=0;index
是Double
,大写D
注意double
和double
之间的区别。“小”双精度是原始类型。另一个是类-java.lang.Double
。您可以在类而不是原语上调用类似于parseDouble(..)
的方法。“big”double也称为“wrapper类”,因为它将原语类型包装到一个类中。它是double
,大写字母D
注意double
和double
之间的区别。“小”双精度是原始类型。另一个是类-java.lang.Double
。您可以在类而不是原语上调用类似于parseDouble(..)
的方法。“big”double也称为“wrapper类”,因为它将原语类型包装到一个类中