This Java program prompts the user to input a number and then determines whether the number is positive, negative, or zero using conditional statements.
The Scanner class is used to read input from the user, and the program prompts the user to enter a number and stores it in the variable num.
The program then uses an if-else statement to determine the sign of the number. If num is greater than 0, it prints the message "Positive Number". If num is less than 0, it prints the message "Negative Number". If num is equal to 0, it prints the message "Zero".
import java.util.Scanner; class Negative_Positive { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the Number : "); int num = input.nextInt(); if(num>0) System.out.println("Positive Number"); else if(num<0) System.out.println("Negative Number"); else System.out.println("Zero"); } }
Enter the Number : 45 Positive Number Enter the Number : -4 Negative Number
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions