Java program to check the given number is positive or negative
KW.java
importjava.util.Scanner;classKW{publicstaticvoidmain(Stringargs[]){intn;Scannersc=newScanner(System.in);System.out.println("———————————————————————————————————————————");System.out.println("Program to check the given number is +ve/-ve");System.out.println("———————————————————————————————————————————");System.out.print("Enter a number ");n=sc.nextInt();if(n<0){System.out.println("\nEntered number is negative");}elseif(n>0){System.out.println("\nEntered number is positive");}else{System.out.println("\nEntered number is zero");}System.out.println("———————————————————————————————————————————");}}
Output
kodingwindow@kw:~$ javac KW.java kodingwindow@kw:~$ java KW
———————————————————————————————————————————
Program to check the given number is +ve/-ve
———————————————————————————————————————————
Enter a number 0
Entered number is zero
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.