Dremendo Tag Line

Check a number is positive or not in Java

if else - Question 2

In this question, we will see how to check if a number is a positive number or not in Java programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q2) Write a program in Java to input a number and check if it is a positive number or not. A positive number is a number which is greater than 0.


import java.util.Scanner;

public class Q2
    public static void main(String args[])
        int n;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a number ");
            System.out.print("Positive Number");
            System.out.print("Not Positive Number");


Enter a number 5
Positive Number