0
I am again in doubt, now the doubt is related to exercise on
Desvio de condicional Simples
using only the command IF
After reading an integer value, calculate and display its square only if the read value is even. Otherwise, the programme shall be terminated without presenting.
I am in doubt what will be my IF condition that indicates that the calculation will only be performed if the number given by the user is even!
I declared three variables
- The number to be entered
- The variable that will present the calculation (in case the number squared)
- Variable to indicate that the value is even!
And my second question is : If I must declare a variable to indicate that the value needs to be even... Or if I only state two variables!
Use the mod, he will capture the rest of the division, for example:
if ( (10 % 2) == 0 )
the expression means: *If the rest of the 10/2 division is equal to 0, then do so. You can also useMath.floorMod
– Valdeir Psr
If you already have some code to solve the problem, it is important that you ask the question, giving more context and highlighting its difficulty
– Isac
Isac.. I didn’t do the code,!
– Carol M
Valdeir...in my case I will use if 10 %2.. since I have not yet seen the Math method!
– Carol M