0

I am running my code fine with int but not so with float. Please help me figure out my mistake.

Its saying possible lossy conversion from double to float despite I gave 11.11 https://code.sololearn.com/cFTRDdBFUN7u/?ref=app

20th Apr 2021, 1:10 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
8 odpowiedzi
+ 2
Remember f is always written with floats
20th Apr 2021, 1:34 AM
Atul [Inactive]
+ 2
public class Program { public static void main(String[] args) { //int myMarks[4]; float myMarks[] = new float[4]; myMarks[0] = 11.11f; System.out.println( myMarks[0]); } }
20th Apr 2021, 1:34 AM
Atul [Inactive]
+ 1
Atul oh, that's a valuable piece of information. Thanks a lot.
20th Apr 2021, 1:36 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
+ 1
Jerry Hobby It's so nice. That looks more like a type conversion. Is that mandatory with all floating points all the time?
20th Apr 2021, 1:43 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
+ 1
No it is an explicit typecasting done by the programmer forcefully. You can use f in floats or can do typecasting by writing float at the beginning
20th Apr 2021, 1:45 AM
Atul [Inactive]
+ 1
Atul Thank you again, that cleared my doubt now.
20th Apr 2021, 1:50 AM
Jagadeesh Gurana
Jagadeesh Gurana - avatar
+ 1
Happy to help you
20th Apr 2021, 1:52 AM
Atul [Inactive]
0
public class Program { public static void main(String[] args) { //int myMarks[4]; float myMarks[] = new float[4]; myMarks[0] = (float) 11.11; System.out.println( myMarks[0]); } }
20th Apr 2021, 1:37 AM
Jerry Hobby
Jerry Hobby - avatar