+ 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

13th Jul 2022, 7:43 PM
Michel Beṭar
Michel Beṭar - avatar
10 odpowiedzi
+ 7
Your problem is: width * width * Math.PI(makes a wrong output) It should be: Math.PI * width * width
13th Jul 2022, 8:43 PM
Jan
Jan - avatar
+ 2
If you not solved or any difficulty in solving, can you share your attempt..
13th Jul 2022, 7:45 PM
Jayakrishna 🇮🇳
+ 2
Yes. As already said use System.out.print(Math.PI*width*width); Instead of System.out.print(width*width*Math.PI);
13th Jul 2022, 8:46 PM
Jayakrishna 🇮🇳
+ 2
Michel Beṭar It produces a double no matter what, but for some reason, the decimals are not completely identical in that output.
13th Jul 2022, 9:04 PM
Jan
Jan - avatar
+ 1
No, can confirm its not broken. I just solved it to verify the issue but everything worked as expected
13th Jul 2022, 7:55 PM
Erarnitox
Erarnitox - avatar
+ 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
13th Jul 2022, 8:22 PM
Michel Beṭar
Michel Beṭar - avatar
+ 1
Jayakrishna🇮🇳 thank you also
13th Jul 2022, 8:47 PM
Michel Beṭar
Michel Beṭar - avatar
+ 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
13th Jul 2022, 10:27 PM
Erarnitox
Erarnitox - avatar
+ 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
13th Jul 2022, 10:53 PM
Erarnitox
Erarnitox - avatar
0
Quantum oh so adding Math.PI in the begging so java already knows the output will be a double?
13th Jul 2022, 8:46 PM
Michel Beṭar
Michel Beṭar - avatar