2011-02-02 43 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

這是Double,資本D

注意doubleDouble之間的區別。 「小」雙是原始類型。另一個是班級 - java.lang.Double。你可以在類上調用類似parseDouble(..)的方法,而不是原始類型。 「big」double也被稱爲「包裝類」,因爲它將原始類型包裝到一個類中。