0
incompatible types: possible lossy conversion from long to int divisors[arr[(int)i]/j]++;
The above expression throws an error pointing '/' can someone help me out?
2 Réponses
+ 3
It means you're trying to implicitly convert a long to an int and may result in a loss in the original value of the long due to the size of a long being greater than that of an int.
Like trying to pour the contents of a pitcher into a glass. The glass may or may not hold what is in the pitcher, depending on how full it is. If there is more in the pitcher than what the glass can hold then the glass will overflow the extra amount resulting in a loss of data.
You'll need to explicitly tell the compiler that this is ok by casting to an int.
+ 1
eg
int[] divisors = {1,2,3,4,5};
long[] arr = {1,2,3,4,5};
int j = 2;
long i = 4;
//divisors[ arr[(int) i] /j ]++;
divisors[ (int) arr[(int) i] /j ]++;