We use the zero
method to test if a number is zero.
(zero? number)
The zero
method accepts just one parameter, the number itself, as illustrated in the syntax section.
The zero
method returns true
if the number is 0 and false
if the number is greater or less than 0.
We use the zero
method to ensure that the calculations we are making does not include a zero. Thus, we use the zero
method to test the number. Let's look at the example below:
(ns clojure.examples.hello(:gen-class));; This program displays Hello World(defn zerro [](def x (zero? 0))(println x)(def x (zero? -1))(println x)(def x (zero? 9))(println x))(zerro)
From the code above:
zerro.
0
into the zero
method. true
because 0
is 0
.-1
into the zero
method. false
because -1
is not 0
.9
into the zero
method. false
because 9
is an odd number and not 0
.zerro
function to execute the code.