Ich möchte die Dauer von 30 cos-Berechnungen anzeigen lassen. Dazu habe ich folgendes programm geschrieben:
nun erhalte ich aber folgende 2 Fehlermeldungen:
C:\java\4>javac Api_d.java
Api_d.java:5: non-static method getTime() cannot be referenced from a static con
text
double time_start=Date.getTime();
^
Api_d.java:11: non-static method getTime() cannot be referenced from a static co
ntext
double time_end=Date.getTime();
^
2 errors
Wie muss ich das programm korrigieren?
Code:
import java.util.*;
class Api_d{
public static void main (String[]arg){
double a=3.14;
double time_start=Date.getTime();
// Cosinus berechnen
for (int i=1; i<=30; i++) {
double c=(Math.cos(Math.toDegrees(a)));
}
double time_end=Date.getTime();
double dauer=time_end-time_start;
System.out.println("Die berechnung dauerte "+dauer+"ms.");
}
}
C:\java\4>javac Api_d.java
Api_d.java:5: non-static method getTime() cannot be referenced from a static con
text
double time_start=Date.getTime();
^
Api_d.java:11: non-static method getTime() cannot be referenced from a static co
ntext
double time_end=Date.getTime();
^
2 errors
Wie muss ich das programm korrigieren?