grach

Magic Sum Array

Jun 8th, 2020
1,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. //Write a program, which prints all unique pairs in an array of integers whose sum is equal to a given number.
  4.  
  5. //Напишете програма, която принтира всички неповторими двойки
  6. //в масив от числа , чиято сума е равна на числото по долу.
  7.  
  8. public class MagicSum {
  9.     public static void main(String[] args) {
  10.         Scanner scan = new Scanner(System.in);
  11.  
  12.         String[] numArray = scan.nextLine().split(" ");
  13.  
  14.         int n = Integer.parseInt(scan.nextLine()); //числото с което сравняваме двойките
  15.  
  16.         int sum = 0;
  17.         for (int i = 0; i < 2; i++) {
  18.             int numbers = Integer.parseInt(scan.nextLine());
  19.  
  20.             sum+=numbers;
  21.             if(sum==n){
  22.                 System.out.print(numbers);
  23.             }
  24.         }
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment