• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# 05. Odd and Even Pairs

a guest Jul 19th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import java.io.IOException;
2. import java.math.BigDecimal;
3. import java.math.BigInteger;
4. import java.util.Scanner;
5.
6. public class Main {
7.     public static void megaputs(Object obj) { System.out.println(obj); }
8.     public static void printf(String format, Object... args) { System.out.printf(format, args); }
9.     public static void javaprint(Object obj) { System.out.print(obj); }
10.
11.
12.     public static void main(String[] args) {
13.         Scanner stdin = new Scanner(System.in);
14.         String line = stdin.nextLine();
15.         String arr[] = line.split(" ");
16.         if(arr.length % 2 != 0) {
17.             megaputs("invalid length");
18.         }
19.         else {
20.             int nums[] = new int[arr.length];
21.             for (int i = 0; i < arr.length; i++) {
22.                 nums[i] = Integer.parseInt(arr[i]);
23.             }
24.             int i = 0, j = i + 1;
25.             while(j < nums.length) {
26.                 if(nums[i] % 2 == 0 ^ nums[j] % 2 == 0) {
27.                     printf("%d, %d -> different\n", nums[i], nums[j]);
28.                 }
29.                 else if(nums[i] % 2 == 0) {
30.                     printf("%d, %d -> both are even\n", nums[i], nums[j]);
31.                 }
32.                 else {
33.                     printf("%d, %d -> both are odd\n", nums[i], nums[j]);
34.                 }
35.                 i+=2;
36.                 j+=2;
37.             }
38.         }
39.     }
40. }
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.
Not a member of Pastebin yet?