New course! Every coder should learn Generative AI!
Try a free lesson0
Why is the output 0?
double p = 2/10; Why is the output 0.0 instead of 0.2? I've been trying to figure out why on my own but I couldn't really understand why it gives out 0 any explanation?
2 Answers
+ 6
khalid raji
Because here 2 and 10 will be treat as integer. So output will be 0. If you want to get in double then just do typecast like
double p = (double) 2 / 10;
+ 2
I Am AJ ! It worked !
Thank you 😊