Write a Java program to test a number is positive or negative


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.util.Scanner;
  2. public class JavaExcercise {
  3.  
  4.  
  5. public static void main(String[] args)
  6. {
  7. Scanner in = new Scanner(System.in);
  8. System.out.print("Input number: ");
  9. int num = in.nextInt();
  10.  
  11. if (num > 0)
  12. {
  13. System.out.println("Number is positive");
  14. }
  15. else if (num < 0)
  16. {
  17. System.out.println("Number is negative");
  18. }
  19. else
  20. {
  21. System.out.println("Number is zero");
  22. }
  23. }
  24. }

Result

java techstudy.org

     





Related Topics




Popular Posts