iAnonGuy

~ Odd or Even? [Hello, Java!]

Feb 24th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. /**
  2.  * Reverses the user-input, splits it, checks if it's even or odd and then returns the result.
  3.  * Equivalent of [ http://pastebin.com/wUeezUDv ] -- Ruby
  4.  * ~ Abk Khan @ [ an0nguy@protonmail.ch -- http://facebook.com/an0nguy ]
  5.  */
  6. import java.util.Scanner;
  7. import java.lang.StringBuilder;
  8.  
  9. public class EvenOdd {
  10.     public static void main(String[] args) {
  11.         Scanner prompt = new Scanner(System.in);
  12.         System.out.print("Input  -- ");
  13.         String numbers = prompt.next();
  14.         StringBuffer buffer = new StringBuffer(numbers).reverse();
  15.         String[] splits = buffer.toString().split("");
  16.         for (String split : splits) {
  17.             int number = Integer.parseInt(split);
  18.             if ((number & 1) == 0) {System.out.println(number+" is Even!");}
  19.             else                   {System.out.println(number+" is Odd!");}
  20.         }
  21.     }
  22. }
Add Comment
Please, Sign In to add comment