Advertisement
CoineTre

JF-ExcArrays08.Magic Sum

Jan 21st, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Exc08MagicSum {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         int[] input = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  8.         int n = scanner.nextInt();
  9.         for (int i = 0; i < input.length; i++) {
  10.             for (int j = i + 1; j < input.length; j++) {
  11.                 if (input[i] + input[j] == n) {
  12.                     System.out.println(input[i] + " " + input[j]);
  13.                 }
  14.             }
  15.         }
  16.     }
  17. }
  18.  
  19. /*
  20. * Write a program, which prints all unique pairs in an array of integers whose sum is equal to a given number.
  21. * */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement