A
A
Alexey Medvedev2015-05-03 21:05:00
Java
Alexey Medvedev, 2015-05-03 21:05:00

Java. How to use number spans?

I do tests on the subject of the application itself in my android application. I'll just give an example. I implement it with such an uncomplicated code (the radioButton buttons are declared, I just don’t include the extra here):

int balls1answer;
int balls2answer;
String resultText;

if (mRadioButton1_1.isChecked()) balls1answer = 1;
if (mRadioButton1_2.isChecked()) balls1answer = 2;
if (mRadioButton1_3.isChecked()) balls1answer = 3;
if (mRadioButton2_1.isChecked()) balls2answer = 1;
if (mRadioButton2_2.isChecked()) balls2answer = 2;
if (mRadioButton2_3.isChecked()) balls2answer = 3;

int resultBalls = balls1answer + balls2answer;

/* Далее идет подсчет и передача результата во вторую активность в зависимости от набранных баллов за ответы */
if (resultBalls == 2 || resultBalls == 3) resultText = "Результат 1";
if (resultBalls == 4 || resultBalls == 5) resultText = "Результат 2";
if (resultBalls == 6) resultText = "Результат 3" ;

In the future, there will be tests with a maximum score of 40 to 200. And the method with "or" (for example, "if score = 2 or if score = 3") will not work for me, as it will be, at least, silly. Yes, and very irrational. The code will be big. Sorry, I'm already a little sleepy, so I could formulate incorrectly.
Question: is it possible to specify some numeric range in the if() method instead of a simple number and an endless repetition of "or"? (e.g. [10-30], [31-40])

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question