You can sort out those unwanted values by just discarding them:
for(i=0;i<tmp.length;i++)
{
if(tmp[i] != 0 )
{
System.out.println(tmp[i]);
}
}
Best otpion would be to set those non valid values to a value of -1, which is regarded as an invalid as it is a negative natural number.
The for loop would then lok like that:
for(i=0;i<tmp.length;i++)
{
if(tmp[i] >= 0 )
{
System.out.println(tmp[i]);
}
}