in java, i have an array of floats, some of them are negative numbers, like :
3.04, 9.02, -4.2, -3.21, 0.02, -0.34
I only want to get the float numbers higher than 2, so I used :
if(number > 2.0 ) print.. etc
but what i get is not only the numbers >2, also the negative numbers :
3.04, 9.02, -4.2, -3.21
what could be the problem ?
Based on comments and question, assuming we have a file named
numbers.txtwith content:this code should do the trick (I ommited exception handling for readibility):
Output: