0
How can I import java.lang.maths to use exponents? (Math.pow)
12 Antworten
+ 6
No need to import Math class..
You can directly use Math.pow(2,3) returns 8.0
+ 5
Katharina Hohenfels
round, pow, ceil are methods of Math class. As you have already used Math.round() without importing so you can also use Math.pow() without importing.
java.lang.*; is default imported package in Java.
Math is a class so it should be java.lang.Math not Java.lang.math
+ 4
java. lang package is always imported by default as it is loaded internally by the JVM.
+ 3
Katharina Hohenfels
According to the current logic, your code is working. Just enter
100
100
5000
And see.
Btw what you want to do?
+ 2
forRounding has been int before, I changed it to double and now it works, even though I don't exactly know why...
+ 2
Katharina Hohenfels
Ok so what inputs you have entered because without changing int to double previous code was also working.
+ 1
Can you tell what you are trying? I mean what is not working? What is expected output?
+ 1
Oh it just worked. I just had to delete the importing part and to change int to double
+ 1
Yeah it worked but e.g. if I entered 2.555 2.555 3.264 and 3 the result was 3.0 instead of 3.264...
+ 1
Math.round() method returns an integer value. And int/int results an int value only..
So there need atleast a double value . Check (double)Math.round() works for previous int forRounding...
0
thanks guys, but then what's the reason that my code does not work?
0
My goal was that the user can input width, height, the surface he has calculated and the decimal places he has rounded and that he can check if his surface calculation is right.