I have to round the numbers of my result. It has to have to digits after the decimal point. One of them is a procedure and the other one is a function. ( I dont know if thats the right terminology in english I am german).
public class Distanz {
//Prozedur
static double x1;
static double y1;
static double x2;
static double y2;
public static void berechneDistanzAlsProzedur ( double x1, double y1, double x2, double y2 ) {
System.out.println("Distanz von p1 und p2 berechnet mit einer Prozedur:" + Math.sqrt((x1*x1-x2*x2)+(y1*y1+y2*y2)) + ".");
//System.out.printf( "Distanz von p1 und p2 berechnet mit einer Prozedur:" + "%.2f" + ".", berechneDistanzAlsProzedur(10.0,8.0,2.0,12.0));
}
//Funktion
public static double berechneDistanzAlsFunktion (double x1, double y1, double x2, double y2){
return Math.sqrt((x1*x1+x2*x2)+(y1*y1+y2*y2));
}
public static void main(String[] args) {
berechneDistanzAlsProzedur(10.0,8.0,2.0,12.0);
//System.out.println("Distanz von p1 und p2 berechnet mit einer Funktion:" + berechneDistanzAlsFunktion(10.0,8.0,2.0,12.0) + ".");
System.out.printf( "Distanz von p1 und p2 berechnet mit einer Funktion:" + "%.2f" + ".", berechneDistanzAlsFunktion(10.0,8.0,2.0,12.0) );
}
// Math.round(cm2inch(number)*100)/100f
}