Android Java math logic issue -


i want message player if score specific score.

what using ..

if(score <= 4){  messageplayer("you scored 1.");  } else if(score <= 19){  messageplayer("you scored 1.");  messageplayer("you scored 5.");  } else if(score <= 49){  messageplayer("you scored 1.");  messageplayer("you scored 5.");  messageplayer("you scored 20.");  } else if(score <= 99){  messageplayer("you scored 1.");  messageplayer("you scored 5.");  messageplayer("you scored 20.");  messageplayer("you scored 50.");  } else if(score >= 100){  messageplayer("you scored 1.");  messageplayer("you scored 5.");  messageplayer("you scored 20.");  messageplayer("you scored 50.");  messageplayer("you scored 100."); } 

the scores want are:

  • 1 point
  • 5
  • 20
  • 50
  • 100

is logic 100% right , accurate? think first 1 score <= 4 wrong, if gets 0 can message you scored 1. , not using score == x, because need message player @ end, when finish, highscore 15.

explicitly exclude 0 this:

if(score > 0 && score <= 4){  messageplayer("you scored 1.");  } 

or better yet, store boundary values in array , solve problem in 1 loop:

int[] boundaries = { 1, 5, 20, 50, 100 };  (int : boundaries) {     if (score >= i) {         messageplayer("you scored " + i);     } } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -