Advertisement
cap7ainjack

Odd and Even Pairs

Oct 17th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OddAndEvenPairs {
  4. public static void main(String[] args) {
  5. Scanner Scan = new Scanner(System.in);
  6.  
  7. //System.out.print(Scan.nextLine().length());
  8. String[] InputLine = Scan.nextLine().split(" ");
  9. int LineLenght = InputLine.length;
  10.  
  11.  
  12. for (int i = 0; i < LineLenght; i++){
  13. int A = Integer.parseInt(InputLine[i]);
  14. int B = Integer.parseInt(InputLine[i + 1]);
  15.  
  16. if (LineLenght % 2 != 0) {
  17. System.out.print("Invalid input");
  18. break;
  19. }
  20. if ((A % 2 == 0) && (B % 2 == 0)) {
  21. System.out.println(A + ", " + B + " -> both are even");
  22. i++;
  23. continue;
  24. }
  25. if ((A % 2 != 0) && (B % 2 != 0)) {
  26. System.out.println(A + ", " + B + " -> both are odd");
  27. i++;
  28. continue;
  29. } else {
  30. System.out.println(A + ", " + B + " -> different");
  31. i++;
  32. }
  33.  
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement