I'd need some help with this. I'm new to java and this is my task:
I have to write code that has an integer array in it. A pair of the arrays values have to be =42
. Then I have to output the pair through normal System.out.println
.
This is the code I've got so far. Maybe I even got this completely wrong.
My problem is getting the program to correctly output what the pairs are that are =42
.
public class Main {
public static void main(String[] args) {
int[] array = { 2, 3, 5, 6, 8, 6, 5, 39, 40, 34 };
for (int i = 0; i < array.length; i++) {
for (int k = 0; k < array.length; k++)
if (array[i] + array[k] == 42)
System.out.println("Found pairs at");
}
}
}