Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Reverses the user-input, splits it, checks if it's even or odd and then returns the result.
- * Equivalent of [ http://pastebin.com/wUeezUDv ] -- Ruby
- * ~ Abk Khan @ [ an0nguy@protonmail.ch -- http://facebook.com/an0nguy ]
- */
- import java.util.Scanner;
- import java.lang.StringBuilder;
- public class EvenOdd {
- public static void main(String[] args) {
- Scanner prompt = new Scanner(System.in);
- System.out.print("Input -- ");
- String numbers = prompt.next();
- StringBuffer buffer = new StringBuffer(numbers).reverse();
- String[] splits = buffer.toString().split("");
- for (String split : splits) {
- int number = Integer.parseInt(split);
- if ((number & 1) == 0) {System.out.println(number+" is Even!");}
- else {System.out.println(number+" is Odd!");}
- }
- }
- }
Add Comment
Please, Sign In to add comment