5
My teacher passed an exercise in which we should use the cases of a switch
to treat intervals, he strictly said that we should use the switch and we cannot use if
and neither while/do
. I’ve tried the following code:
switch(saldo){
case 0..200:
//...
break;
}
However, I know that java does not work that way, I have already researched the internet an equivalent to ..
and I didn’t find anything that would solve my problem, there’s how to do it?
Enunciation :
4) A bank shall grant a special variable credit to its customers with the average balance in the last year. Make an algorithm that reads the balance average of a customer and calculate the value of the credit according to the table below. Show a message stating the average balance and the value credit. (use case-of command and do not repeat)
Average balance Percentage
from 0 to 200 no credit
from 201 to 400 20% of the average balance
from 401 to 600 30% of the average balance
above 601 40 % of the average balance
These intervals are what ? Time?
– Roknauta
Do you have the statement of this? I did not understand very well.
– user28595
No, these ranges are integer numbers. For example, if the balance >-1 and <201 I do something, if > 200 is something else, and so on.
– Daniel Santos