• Skip to main content
  • Skip to primary sidebar

Founder at work

Master the skills to create and launch your next SaaS company

  • About Me
  • Reviews
  • Resources
  • Community
  • Contact
  • Lessons
  • Series
  • Search
  • Login

Have you ever wanted to see if a number really is even or odd?

October 24, 2012 by Rick Hernandez Leave a Comment


import java.util.Scanner; 

public class EvenOrOdd
{
  public static void main (String []args)
  {
     int EvenOrOdd = 0; // set EvenOrOdd to zero
     
     Scanner input = new Scanner(System.in); // create a new object scanner
     
     System.out.println("Welcome to the even or odd program enter your number: "); // prints message to console
     
     EvenOrOdd = input.nextInt(); // sets input of number to EvenOrOdd
     
     int Number = isEven(EvenOrOdd); // EvenOrOdd gets passed to method
     
     while (Number != 0)
     {    
         
          int CheckMe = isEven(EvenOrOdd);
          
          if (CheckMe == 0)
          {
              System.exit(0);
          }
          
          if(CheckMe > 0)
          {
              System.out.println("Your Number is Even");
          }
          else
                  {
                      System.out.println("Your Number is odd");
                  }
          
         
          
          System.out.println("Enter the next number? (Type 0 to exit)");
          EvenOrOdd = input.nextInt();  

     } // end of the while loop
     
  } // end of main method
  
  /****************Method isEven*********************/
  
  public static int isEven(int CheckMe)
  {
      if (CheckMe % 2 == 0)
      {       
          
          return CheckMe;
      }
      else
      {
          CheckMe = -1;
          return CheckMe;
      }
      
      
  }// end of isEven method
  
}// end of class 


Rick Hernandez

I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Filed Under: Java, Programming

Primary Sidebar

Learn How To Take Your Idea And Convert It Into An App From Scratch Even If You Have Never Written A Single Line Of Code.

  • How to Find Your Next Great App Idea
  • The Secret To Getting PAID To Build Your Own App
  • How To Create Your App (SaaS, Mobile, VR, AR, Game)
  • How To Monetize Your Apps
Learn More
4.82 Ratings

Copyright © 2025 · JSecademy Blog Theme on Genesis Framework · WordPress · Log in