0
Consider this: a=Math.pow(b,c). Why can't I declare 'a' as integer? The program can run only when I change it to double.
5 ответов
+ 4
That is because, Math.pow() function takes 2 arguments which are double and it also returns a double type value.
Well why is that?
Because if you try to do power of some number which has floating point value then int will not work.
+ 4
Math.pow always returns a double, but you can explicitly cast it into an integer.
int a = (int) Math.pow(2.0, 3.3);
Of course you will lose all the decimals after the dot, if there were any, this is like floor rounding.
+ 3
Yes exactly Tibor Santa
When you try to run without casting with an integer,
Warning message we get is : it can be lossy conversation
so they ask us to use double for it.
0
Coding Panda
Ouhhh now I get it. Thank you!
0
I see