Write a Java program to get a number from the user and print whether it is positive or negative.

1. Write a Java program to get a number from the user and print whether it is positive or negative.


Create a package name w3, then create a class named EX1.

copy this solution and past on your netbeans editor.

Solution:





package w3;

import java.util.Scanner;


public class EX1 {
   
    public static void main(String[] args) {
       
       Scanner input = new Scanner(System.in);
       
     int num1;
    
        System.out.println("Enter Any Number : ");
     num1 = input.nextInt();
    
     if (num1>0){
         System.out.println("Number is positve");
     }
         else if (num1<0){
         System.out.println("number is Nagative");       
                 }   
                 else{
         System.out.println("Zero");        }
     }
    }
   


 

 << Previous <<        



 >> Next >>











 

Comments