How can I import java.lang.maths to use exponents? (Math.pow) | Sololearn: Learn to code for FREE!


How can I import java.lang.maths to use exponents? (Math.pow)

6/20/2021 11:09:39 AM

Katharina Hohenfels🇩🇪

12 Answers

New Answer


No need to import Math class.. You can directly use Math.pow(2,3) returns 8.0


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


java. lang package is always imported by default as it is loaded internally by the JVM.


Katharina Hohenfels According to the current logic, your code is working. Just enter 100 100 5000 And see. Btw what you want to do?


forRounding has been int before, I changed it to double and now it works, even though I don't exactly know why...


Katharina Hohenfels Ok so what inputs you have entered because without changing int to double previous code was also working.


Can you tell what you are trying? I mean what is not working? What is expected output?


Oh it just worked. I just had to delete the importing part and to change int to double


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...


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...


thanks guys, but then what's the reason that my code does not work?


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.