SHARE
TWEET

EvenOdd

kocev Feb 18th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.regex.Pattern;
  3.  
  4. public class OddOrEven {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String input = scanner.nextLine();
  8.         int number;
  9.         Pattern pattern = Pattern.compile("[0-9]+");
  10.         while (!pattern.matcher(input).matches()){
  11.             System.out.println("Wrong input! Please enter digit instead symbol.");
  12.             input = scanner.nextLine();
  13.  
  14.         }
  15.  
  16.         number = Integer.parseInt(input);
  17.         System.out.println(number != 0?number%2 == 0?"Even":"Odd":"Zero is neither even nor odd.");
  18.     }
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top