Even Number:- The Number, who can divide by 2 completely and a reminder will 0 called Even Number.
Odd Number:- The Number, Who always divide by 1 and itself. when the number will divide with 2 and its reminder will never come 0.
Why need it…
Sometimes we need to use only Even or Odd numbers. At that time we need to find out the Even or Odd number first.
Find Even Numbers…
val a:Int = 26;
if(a%2==0){
print("$a is an Even number")
}else{
print("$a is an Odd number")
}
- Create a variable to store an integer value.
- And use if else condition, because this condition is work on boolean (true and false)
- I have used % Operator to find out a reminder.
- (a%2==0 ) This means a is a variable that is store in 26, and divide by 2. if reminder will come 0 means the condition is true and the code will execute in if body {}. if reminder will come except 0 that means the condition is false and code will execute in else body {}.
- I am printing an Even number in the if body and it will print when the condition will be true.
- Other than it will print an odd number.
Result: 26 is an Even number
Because the condition is true here.
I hope it will help someone.
Thanks:)