xdxdxd123

Untitled

Jun 17th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. Java
  2.  
  3. (Even or Odd) Write a method isEven that uses the remainder operator (%) to determine
  4. whether an integer is even. The method should take an integer argument and return true if the integer
  5. is even and false otherwise. Incorporate this method into an application that inputs a sequence
  6. of integers (one at a time) and determines whether each is even or odd.
  7.  
  8. Expert Answer
  9. Anonymous
  10. Anonymous answered this Was this answer helpful?
  11. 0
  12. 0
  13. 49 answers
  14. The (Even or Odd) Write a method isEven that uses the remainder operator (%) to determine
  15. whether an integer is even. The method should take an integer argument and return true if the integer
  16. is even and false otherwise. Incorporate this method into an application that inputs a sequence
  17. of integers (one at a time) and determines whether each is even or odd. the java programming code is
  18.  
  19. import java.util.*;
  20. class EvenOdd
  21. {
  22.  
  23. public void checkEvenOdd()
  24. {
  25. Scanner input = new Scanner(System.in);
  26.  
  27. System.out.printf("%s\n%s\n %s\n %s\n","enter numbers to determine if they are even or odd");
  28. while(input.hasNext())
  29. {
  30.  
  31. int number=input.nextInt();
  32. if(isEven(number) )
  33. {
  34. System.out.printf("%d is even",number);
  35. }
  36. else
  37. {
  38. System.out.printf("%d is odd",number);
  39. }
  40. }
  41. }
  42.  
  43. public static boolean isEven(int number)
  44. {
  45. return number % 2 == 0;
  46. }
  47. }
  48.  
  49. class EvenOddTest
  50. {
  51. public static void main(String []args)
  52. {
  53. EvenOdd eo =new EvenOdd();
  54. eo.checkEvenOdd();
  55. }
  56. }
  57.  
  58. output:65
  59.  
  60. 65 is odd.
Add Comment
Please, Sign In to add comment