Positive or Negative Number

Madhu PalleMadhu Palle
1 min read

Explanation :

Step 1: Take a number from the user by using the Scanner class object.

Step 2: If the given number is < 0 then it is a negative number otherwise, it is a positive number.

Java Code :

//postive or negative

import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a Number = ");
        int number = sc.nextInt();
        if(number < 0){
            System.out.println("Negative Number");
        }
        else{
            System.out.println("Positive Number");
        }
    }
}

C++ code :

#include<iostream>
using namespace std;

int main(){
    int number;
    cout<<"Enter a number = ";
    cin >> number ;
    if(number < 0 ){
        cout<<"Negative Number" <<endl;
    }
    else{
        cout<<"Positive Number" << endl;
    }
}

Python code :

# positive or negative

number = int(input("Enter a number = "))
if number < 0:
    print("Negative number")
else:
    print("Positve Number")

0
Subscribe to my newsletter

Read articles from Madhu Palle directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Madhu Palle
Madhu Palle

IIIT - N Software Geek. Startup Enthusiast. Build for the Future.