It shows an infinite loop

for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++){//////// 
               if ((a[i] + a[j]) == sum) 
                    System.out.println(a[i]+" and "+a[j]); 
       }
 }

take loops till n
you need spaces before and after and like a[i]+“ and ”+a[j] and you have to print the smaller of a[j] and a[i] first and then the latter
if this solves your doubt please mark it as resolved :slight_smile: