Home »
VB.Net »
VB.Net Programs
VB.Net program to check the given number is POSITIVE or NEGATIVE using conditional operator
By Nidhi Last Updated : October 13, 2024
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 »