Write a Java method to find number is even number or not


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.  
  3. public class Javaexcercise
  4. {
  5. public static void main(String[] args)
  6. {
  7. Scanner console = new Scanner(System.in);
  8. int num;
  9.  
  10. System.out.print("Enter an integer: ");
  11. num = console.nextInt();
  12.  
  13. if(isEven(num))
  14. {
  15. System.out.println("Number is even");
  16. }
  17. else
  18. {
  19. System.out.println("Number is odd");
  20. }
  21. }
  22.  
  23. public static boolean isEven(int number)
  24. {
  25. if(number % 2 == 0)
  26. {
  27. return true;
  28. }
  29. else
  30. {
  31. return false;
  32. }
  33. }
  34. }

Result

java techstudy.org

     





Related Topics




Popular Posts