Brauche dringend Hilfe. Ich soll diese Berechnung(Abstand zweier Punkte) als Funktionsprozedur und als Prozedur lösen und beides ausgeben. Ich schaffe es aber nicht.. wo liegt mein Fehler? Bei system.out.println kommt die fehlermeldung 'void' type not allowed here. Habe viel versucht aber mache es irgendwie nur schlimmer...
Java:
public class Distanz {
static double n;
static double n1;
public static void berechneDistanzAlsProzedurp ( double x1, double y1, double x2, double y2){
n = x1 - x2;
n1 = y1 - y2;
n = n * n;
n1 = n1 * n1;
n = n + n1;
n = Math.sqrt(n);
}
public static double berechneDistanzAlsFunktion ( double x1, double y1, double x2, double y2){
double s = 0;
double s1 = 0;
s = x1 - x2;
s1 = y1 - y2;
s = s * s;
s1 = s1 * s1;
s = s + s1;
s = Math.sqrt(s);
return s;
}
public static void main(String[] args) {
System.out.println("Distanz von p1 und p2 berechnet mit einer Prozedur:" + berechneDistanzAlsProzedurp(10, 8, 2, 12));
System.out.println("Distanz von p1 und p2 berechnet mit einer Funktion:" + berechneDistanzAlsFunktion(10, 8, 2, 12));
}
}
Zuletzt bearbeitet von einem Moderator: