What is the problem in this simple line of code???? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

What is the problem in this simple line of code????

In the following code, the compiler is returning conversion error when all of my variables are Integers.. int a,e,c,d; d=0 for(a=5;a>=0;a--) { e=c*(Math.pow(16,d)); d++ } System.out.println(e); https://code.sololearn.com/cV70J0S30JiY/?ref=app

8th Sep 2017, 11:57 AM
Neil Bhowmik
Neil Bhowmik - avatar
9 Respostas
+ 4
how did no one mention that most of the math operators produce a result of type double... so you have to do e = c*(int)(Math.pow(16,d)); in order to type cast the math back to int bwfore you try storing it in int e, or you do e = (int)(c*(Math.pow(16,d)));
8th Sep 2017, 5:05 PM
Will
+ 1
add at the very first import java.Math
8th Sep 2017, 12:32 PM
Faramarz Monazami
Faramarz Monazami - avatar
+ 1
kk thanx
8th Sep 2017, 12:33 PM
Neil Bhowmik
Neil Bhowmik - avatar
+ 1
thank you....these ppl couldn't understand this thing for so long....I knw the basics..... anyways thanx again
8th Sep 2017, 5:16 PM
Neil Bhowmik
Neil Bhowmik - avatar
0
it's showing lossy conversion from double to int...how????
8th Sep 2017, 11:58 AM
Neil Bhowmik
Neil Bhowmik - avatar
0
you didnt assign value to c!
8th Sep 2017, 12:22 PM
Faramarz Monazami
Faramarz Monazami - avatar
0
okay take c as 3....then?? It's showing the same thing
8th Sep 2017, 12:27 PM
Neil Bhowmik
Neil Bhowmik - avatar
0
forgot to include math class in this editor you have to add the classes for java
8th Sep 2017, 12:28 PM
Faramarz Monazami
Faramarz Monazami - avatar
0
okay wait
8th Sep 2017, 12:29 PM
Neil Bhowmik
Neil Bhowmik - avatar