double runde(double x, int n) {
if (n < 0) {
throw new IllegalArgumentException("Anzahl der Nachkommastellen darf nicht negativ sein.");
return 0.0 ; }
if (n==x) {/* Ist n=x? Wenn ja, dann nicht runden*/
return x ; } /* X dementsprechend als Rückgabewert */
if (n>0) {/* Test ob n größer null ist*/
return Math.round(x*Math.pow(10,n))/Math.pow(10,n) ; }}
Hey, I don't get why return 0.0 should be a unreachable statement. I tried to build a method which rounds a number to a given decimal place.
besides there shall be a missing return statement.
Thank you for your help!
Aucun commentaire:
Enregistrer un commentaire