Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Java
- (Even or Odd) Write a method isEven that uses the remainder operator (%) to determine
- whether an integer is even. The method should take an integer argument and return true if the integer
- is even and false otherwise. Incorporate this method into an application that inputs a sequence
- of integers (one at a time) and determines whether each is even or odd.
- Expert Answer
- Anonymous
- Anonymous answered this Was this answer helpful?
- 0
- 0
- 49 answers
- The (Even or Odd) Write a method isEven that uses the remainder operator (%) to determine
- whether an integer is even. The method should take an integer argument and return true if the integer
- is even and false otherwise. Incorporate this method into an application that inputs a sequence
- of integers (one at a time) and determines whether each is even or odd. the java programming code is
- import java.util.*;
- class EvenOdd
- {
- public void checkEvenOdd()
- {
- Scanner input = new Scanner(System.in);
- System.out.printf("%s\n%s\n %s\n %s\n","enter numbers to determine if they are even or odd");
- while(input.hasNext())
- {
- int number=input.nextInt();
- if(isEven(number) )
- {
- System.out.printf("%d is even",number);
- }
- else
- {
- System.out.printf("%d is odd",number);
- }
- }
- }
- public static boolean isEven(int number)
- {
- return number % 2 == 0;
- }
- }
- class EvenOddTest
- {
- public static void main(String []args)
- {
- EvenOdd eo =new EvenOdd();
- eo.checkEvenOdd();
- }
- }
- output:65
- 65 is odd.
Add Comment
Please, Sign In to add comment