Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- //Write a program, which prints all unique pairs in an array of integers whose sum is equal to a given number.
- //Напишете програма, която принтира всички неповторими двойки
- //в масив от числа , чиято сума е равна на числото по долу.
- public class MagicSum {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String[] numArray = scan.nextLine().split(" ");
- int n = Integer.parseInt(scan.nextLine()); //числото с което сравняваме двойките
- int sum = 0;
- for (int i = 0; i < 2; i++) {
- int numbers = Integer.parseInt(scan.nextLine());
- sum+=numbers;
- if(sum==n){
- System.out.print(numbers);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment