Write a Kotlin Program to Check Whether a Number is Positive or Negative

In Kotlin, you can check whether a number is positive or negative by simply comparing it to zero.

If the number is greater than zero, it is positive, and if it is less than zero, it is negative.

Here is an example program that demonstrates this:

fun main() {
    val number = -5

    if (number > 0) {
        println("The number $number is positive.")
    } else if (number < 0) {
        println("The number $number is negative.")
    } else {
        println("The number is zero.")
    }
}

In this program, we declare a variable number and assign it a value of -5.

We then use an if-else statement to check whether the number is positive or negative.

If the number is greater than zero, we print a message saying that the number is positive.

If the number is less than zero, we print a message saying that the number is negative.

If the number is equal to zero, we print a message saying that the number is zero.

You can run this program in any Kotlin compiler or IDE and it will output “The number -5 is negative.”

This program can be easily adapted to check the sign of any number by simply changing the value of the number variable.

In conclusion, checking whether a number is positive or negative in Kotlin is a simple task that can be accomplished using a basic if-else statement.

By comparing the number to zero, you can easily determine whether it is positive, negative, or zero.