VB.Net program to check the given number is POSITIVE or NEGATIVE using conditional operator

Here, we are going to learn how to check the given number is POSITIVE or NEGATIVE using conditional operator in VB.Net?
Submitted by Nidhi, on November 26, 2020 [Last updated : February 18, 2023]

Checking POSITIVE or NEGATIVE number using conditional operator

Here, we will read an integer number and check the given number is POSITIVE or NEGATIVE, and then print the appropriate message on the console screen.

VB.Net code to check POSITIVE or NEGATIVE number using conditional operator

The source code to check the given number is POSITIVE or NEGATIVE is given below. The given program is compiled and executed successfully.

'VB.Net program to check the given number is 
'POSITIVE or NEGATIVE.

Module Module1
 
    Sub Main()

        Dim num As Integer = 0
        Dim result As String

        Console.Write("Enter number: ")
        num = Integer.Parse(Console.ReadLine())

        result = If((num < 0), "Number is NEGATIVE", "Number is POSITIVE")
        Console.WriteLine(result)

        Console.ReadLine()
    End Sub

End Module

Output:

Enter number: -3
Number is NEGATIVE

Explanation:

In the above program, we created a module Module1 that contains the Main() method. In the Main() method we created a local variable num and result. After that, we read the value of num.

result = If((num < 0), "Number is NEGATIVE", "Number is POSITIVE")

In the above code, we checked the given number is POSITIVE or NEGATIVE, after that print the appropriate message on the console screen.

VB.Net Basic Programs »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.