Array.22.

PHOTO EMBED

Sun Dec 11 2022 13:31:47 GMT+0000 (Coordinated Universal Time)

Saved by @KutasKozla #java

import java.util.Scanner;

public class PJJJeden {

    public static void main(String[] args) {
        int[] tab = {1, 2, 3, 4, 5, 7, 8, 9, 10, 0};
        Scanner sc = new Scanner(System.in);
        System.out.print("Wartość: ");
        int wart = sc.nextInt();
        System.out.println("Wpisana wartość będzie sumą elementów tablicy: ");
        for(int i = 0; i < tab.length; i++){
            for(int j = 0; j <tab.length; j++){
                if ((tab[i] + tab[j] == wart)||(tab[j] + tab[i] == wart)){
                    System.out.println(tab[i] + " " + tab[j] );}
            }
        }
    }
}
content_copyCOPY

Write a Java program to find all pairs of elements in an array whose sum is equal to a specified number.

https://www.w3resource.com/java-exercises/array/java-array-exercise-22.php