The program below is the answer to Deitel’s Java How to Program (9th Edition) Chapter 2 Exercise 2.25.
Question: Write an application that reads an integer and determines and prints whether it’s odd or even. [Hint: Use the remainder operator. An even number is a multiple of 2. Any multiple of 2 leaves a remainder of 0 when divided by 2.]
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.25 - Odd Or Even<br /> * This Program Determines If A Number Is Odd Or Even<br /> *<br /> */ <br /><br />import java.util.Scanner;<br /><br />public class Ex02_25 {<br /> public static void main (String [] args) {<br /><br /> Scanner numbers = new Scanner (System.in); <br /><br /> int num;<br /> int check;<br /> <br /> System.out.print ("Enter A Number: ");<br /> num = numbers.nextInt();<br /> check = num%2;<br /> <br /> if (check == 0)<br /> System.out.printf ("nThe Number %d is EVEN.n", num);<br /> if (check != 0)<br /> System.out.printf ("nThe Number %d is ODD.n", num);<br /><br /> }<br />}<br /> |