Asenov

Odd and Even Pairs

Mar 17th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OddAndEvenPairs {
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.         String str = input.nextLine();
  7.         String[] strArr = str.split(" ");
  8.         if (strArr.length % 2 != 0){
  9.             System.out.println("Ivalid length");
  10.         }
  11.         else
  12.         {
  13.             for (int i = 0; i < strArr.length - 1; i+=2){
  14.                 int a = Integer.parseInt(strArr[i]);
  15.                 int b = Integer.parseInt(strArr[i + 1]);
  16.                 if ((a + b) % 2 != 0){
  17.                     System.out.printf("%d, %d -> different\n", a, b);
  18.                 }
  19.                 else if(a % 2 != 0){
  20.                     System.out.printf("%d, %d -> both are odd\n", a, b);
  21.                 }
  22.                 else {
  23.                     System.out.printf("%d, %d -> both are even\n", a, b);
  24.                 }
  25.             }
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment