Display 1, 2, 3 if you receive odd numbers

Asked

Viewed 56 times

1

I need that in the textview displays in order 1, 2, 3, 4 etc. But the value it receives from dados.getdia() is always 3, 5, 7, 9, 11 etc. I have tried several things.

In this code below it works up to when it gets 5, then when it gets 7, it displays 5 instead of 4, which would be correct. 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));
}
  • It seems easy to solve your problem, but I barely understood what you tried to explain. Could you elaborate a little more? Do you want to show only odd days? or only pairs?

  • I want to display 1,2,3 however I get odd, but it seems that I managed to solve here, I made a counter and subtract the day - counted, I’m doing the tests here

1 answer

1


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

You’ll have to treat them considering the difference between them to find the position.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.