Reputation: 51
Let's assume I have a vector
Vec[5] = {a1, a2, a3, a4, a5}
How can I make a method that multiplies:
a1*a2, a1*a3, a1*a4, a1*a5
a2*a3, a2*a4, a2*a5
a3*a4, a3*a5
a4*a5
Thanks!
Upvotes: 2
Views: 296
Reputation: 4551
Use a nested loop:
for (int i = 0; i < vec.length - 1; i++)
for (int j = i + 1; j < vec.length; j++)
// do something with i*j
System.out.print(i*j + " ");
Upvotes: 2