Is the number odd or even – Java Program

What it does:

A simple program with allows the user to enter an integer where it will use an if to see if the number they have entered is odd or even. It will then print out the number they have entered along with the result of if it is odd or even.

Code:

</pre>
public class OddAndEvenNumbers
 {
 public static void main(String[] args)
 {
 Scanner keyboard = new Scanner(System.in);

int numberEntered;

System.out.println("A program to find if the number entered is odd or even.");

System.out.println("Please enter an integer");

numberEntered=keyboard.nextInt();

if (numberEntered %2 ==0)
 {
 System.out.println("The number your entered was " +numberEntered + " and it is even");
 }//if

else
 {
 System.out.println("The number your entered was " +numberEntered + " and it is odd");
 }//else
 }//main
 }//class
<pre>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s