0

It maybe silly question but I need to check if the value of a cell is NAN which means (1/zero) and then convert it to zero I tried the following code

for(i=0;i<5;i++){
do some calculation to get cell[i]
if(cell[i]==NAN)cells[i]=0;}

But this doesn't work because java can't recoginize the variable NAN what I should put instead of NAN Thanks in advance

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216

2 Answers2

0

You need to use the Double.isNan(double) method. Comparisons with == with NaNs are always false.

if (Double.isNan(cell[i]))
rgettman
  • 176,041
  • 30
  • 275
  • 357
0

Depending on the type of your array, use Double.isNaN() or Float.isNaN().

Thomas
  • 174,939
  • 50
  • 355
  • 478