Write a Java program that reads an integer and check whether it is negative, zero, or positive


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

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

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

Result

java techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.