2011-02-02 8 views
0

に関するヘルプ、私はこのプログラムを実行すると、私はこれらのエラーを取得:クラスの予想されるエラー。簡単なプログラム

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); 

    } 
} 

答えて

6

それは資本D

で、DoubleだがdoubleDoubleの区別に注意してください。 「小さい」倍精度はプリミティブ型です。もう1つはクラスjava.lang.Doubleです。プリミティブではなく、クラスにparseDouble(..)のようなメソッドを呼び出すことができます。 「ビッグ」の倍数は、プリミティブ型をクラスにラップするため、「ラッパークラス」とも呼ばれます。

関連する問題