Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Arrays;
- import java.util.Scanner;
- public class MagicSum_08 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String [] numbers = scanner.nextLine().split(" ");
- //"1 7 6 2 19 23".split(" ") -> ["1", "7", "6", "2", "19", 23]
- int magicSum = Integer.parseInt(scanner.nextLine());
- //всички двойки числа, които могат да се образуват
- for (int index = 0; index < numbers.length - 1; index++) {
- int currentElement = Integer.parseInt(numbers[index]);
- for (int index1 = index + 1; index1 <= numbers.length - 1; index1++) {
- int nextElement = Integer.parseInt(numbers[index1]);
- if (currentElement + nextElement == magicSum) {
- System.out.println(currentElement + " " + nextElement);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment