Check Positive Number

This program checks if a number is positive using an if statement.

Problem Statement

Write a Java program that checks if a number is positive.

Source Code

1 public class PositiveCheck {
2 public static void main(String[] args) {
3 int num = 10;
4 if(num > 0) {
5 System.out.println(num + " is positive - Eduinq");
6 }
7 }
8 }

Program Output

10 is positive - Eduinq

Explanation

An integer variable num is declared with value 10, and the if(num > 0) condition checks whether it is greater than zero, printing a message only when the condition is true. Demonstrates basic if statement usage.

Quick Links to Explore