+ 2
For those who did the java course
the shapes problem is broken right?. Test case #3 keeps yelling at me. I've seen lots of profiles and seems like nobody have solved it. Everyone got 99% of the java course
10 ответов
+ 7
Your problem is: width * width * Math.PI(makes a wrong output)
It should be: Math.PI * width * width
+ 2
If you not solved or any difficulty in solving, can you share your attempt..
+ 2
Yes. As already said use
System.out.print(Math.PI*width*width);
Instead of
System.out.print(width*width*Math.PI);
+ 2
Michel Beṭar It produces a double no matter what, but for some reason, the decimals are not completely identical in that output.
+ 1
No, can confirm its not broken. I just solved it to verify the issue but everything worked as expected
+ 1
Jayakrishna🇮🇳 - If you not solved or any difficulty in solving, can you share your attempt..
https://code.sololearn.com/c2ec2e567oWT/?ref=app
I don't if you can see private code bits having the link. If you cannot see it ask me to make it public
+ 1
Jayakrishna🇮🇳 thank you also
+ 1
This is floating point arithmetic at it's finest. Michel Beṭar your solution should actually be more accurate! Take at the IEEE floating point standard.
I really think sololearn should have a threshhold here for the correct solution. Maybe if it is correct it to 4 digits or something
+ 1
I made a small program to experiment around a bit. Most of the time width*width*PI is most accurate: int multiplication is perfect(except for int overflows). float mutiplication almost alwas has an error this is due to a limitation in the notation/storage.
So if you only do one float multiplication, the error should be smaller in most cases.
If you want to experiment around yourself:
https://code.sololearn.com/cz50tEnrRbRi/?ref=app
0
Quantum oh so adding Math.PI in the begging so java already knows the output will be a double?