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
8 Antworten
+ 2
Remember f is always written with floats
+ 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]);
}
}
+ 1
Atul oh, that's a valuable piece of information. Thanks a lot.
+ 1
Jerry Hobby It's so nice. That looks more like a type conversion. Is that mandatory with all floating points all the time?
+ 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
+ 1
Atul Thank you again, that cleared my doubt now.
+ 1
Happy to help you
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]);
}
}