When I assign some value (< 1) to float or double without any suffix 'f' or 'd' respectively, then why the output shows 0.0? My program is
public class Example {
double a = 1/2d;
float b = 1/2f;
double c = 1/2;
float d = 1/2;
public static void main(String[] args) {
Example e = new Example();
System.out.println("a: "+e.a);
System.out.println("b: "+e.b);
System.out.println("c: "+e.c);
System.out.println("d: "+e.d);
}
}
The output is
a: 0.5 b: 0.5 c: 0.0 d: 0.0