Checking if a number is odd or even in Ruby - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: Ruby 3 Tutorials, exercises and examples (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=17) +--- Thread: Checking if a number is odd or even in Ruby (/showthread.php?tid=2501) |
Checking if a number is odd or even in Ruby - Qomplainerz - 02-28-2021 Example 1. Let's see if 1 is even by executing the following code: Quote:puts 1.even? This will print "false" on the screen, because 1 is not even. Example 2. Let's see if 2 isĀ even by executing the following code: Quote:puts 2.even? This will print "true" on the screen, because 2 is even. Example 3. Let's see if 1 is odd by executing the following code: Quote:puts 1.odd? This will print "true" on the screen, because 1 is odd. Example 4. Let's see if 2 is odd by executing the following code: Quote:puts 2.odd? This will print "false" on the screen, because 2 is not odd. |