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!
You throw an exception the statement just before.
This ends the execution of the method.
It's possible you're confused by the random indentation and braces placement. You should try to stick to a standard formatting. Writing clean code helps avoiding bugs.