20th Jun 2021, 11:09 AM
Sndr Brst🇩🇪
Sndr Brst🇩🇪 - avatar
12 ответов
+ 6
No need to import Math class.. You can directly use Math.pow(2,3) returns 8.0
20th Jun 2021, 11:18 AM
Jayakrishna 🇮🇳
+ 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
20th Jun 2021, 11:30 AM
A͢J
A͢J - avatar
+ 4
java. lang package is always imported by default as it is loaded internally by the JVM.
20th Jun 2021, 11:21 AM
Nanda Balakrishnan
+ 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?
20th Jun 2021, 11:34 AM
A͢J
A͢J - avatar
+ 2
forRounding has been int before, I changed it to double and now it works, even though I don't exactly know why...
20th Jun 2021, 11:38 AM
Sndr Brst🇩🇪
Sndr Brst🇩🇪 - avatar
+ 2
Katharina Hohenfels Ok so what inputs you have entered because without changing int to double previous code was also working.
20th Jun 2021, 11:43 AM
A͢J
A͢J - avatar
+ 1
Can you tell what you are trying? I mean what is not working? What is expected output?
20th Jun 2021, 11:33 AM
Jayakrishna 🇮🇳
+ 1
Oh it just worked. I just had to delete the importing part and to change int to double
20th Jun 2021, 11:37 AM
Sndr Brst🇩🇪
Sndr Brst🇩🇪 - avatar
+ 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...
20th Jun 2021, 12:00 PM
Sndr Brst🇩🇪
Sndr Brst🇩🇪 - avatar
+ 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...
20th Jun 2021, 12:17 PM
Jayakrishna 🇮🇳
0
thanks guys, but then what's the reason that my code does not work?
20th Jun 2021, 11:30 AM
Sndr Brst🇩🇪
Sndr Brst🇩🇪 - avatar
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.
20th Jun 2021, 11:40 AM
Sndr Brst🇩🇪
Sndr Brst🇩🇪 - avatar