Showing posts with label odd and even numbers in java using methods. Show all posts
Showing posts with label odd and even numbers in java using methods. Show all posts

Wednesday, July 12, 2017

Odd and Even Numbers in Java Using Methods

In this sample program it will ask the user to give a number and then our program written in Java will check if the given number is an odd or even numbers using methods in Java.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output



Program Listing

// Problem : Write a program in Java that will check if the given number by the user is an
//           Odd or Even Number.         
// Date:  June 28, 2015
// Written By: Mr. Jake R. Pomperada, MAED-IT
// Email Address: jakerpomperada@yahoo.com and jakerpomperada@gmail.com

import java.util.Scanner;


class odd_even_checker {
    public int check_odd_even_number(int value)
    {
      if((value % 2) == 0) 
System.out.println("The given number is " + value + " is Even Number.");
else
System.out.println("The given number is " + value +  " is Odd Number.");
    return 0;
    }

 
public static void main(String args[]) {
  Scanner scan = new Scanner(System.in);
   char a;
do
    {
  // creating of an object
  
  odd_even_checker num = new odd_even_checker();
      
  System.out.println();
  System.out.println("===== ODD OR EVEN NUMBER CHECKER =====");
  System.out.println();
  System.out.print("Enter a Number :  ");
  int number_given =   scan.nextInt();
  
  System.out.println();
     num.check_odd_even_number(number_given);
  System.out.println("\n\n");
  System.out.print("Do you Want To Continue (Y/N) :=> ");
   a=scan.next().charAt(0);

   } while(a=='Y'|| a=='y');
          System.out.println("\n");
          System.out.println("\t ===== END OF PROGRAM ======");
         System.out.println("\n");
 }
  
   } // End of Program