Display 1, 2, 3 if you receive odd numbers

1

I need in textview to display in order 1, 2, 3, 4 etc. But the value he receives from dados.getdia() is always 3, 5, 7, 9, 11 etc. I've tried several things.

In this code below it works until you get 5, then when you get 7, it displays 5 instead of 4, which would be the correct one. How can I do this?

int dia = dados.getDia();
if(dia == 3){
    Log.d(TAG,"entrou Dia ==3");
    int dia2 = dia-1 ;
    txv_dia.setText(String.valueOf(dia2));
}else if(dia >3){
    Log.d(TAG,"entrou Dia >3");
    int dia2 = dia-3 ;
    txv_dia.setText(String.valueOf(dia2));
}
    
asked by anonymous 30.09.2017 / 02:29

1 answer

1

As I believe you want to print the position of prime numbers, you can not have == 3,> 3 and -3, as the difference between numbers always increases.

You'll have to treat them by considering this difference between them to find the position.

    
30.09.2017 / 13:18