I want to loop through my arraylist such a way that,
if it's int i = 0 = b(0), it will eliminate b(0) and multiply
b.get(1)*b.get(2) = 3*6
if it's int i = 1 = b(1), it will eliminate b(1) and multiply
b.get(0)*b.get(2) = 1*6
if it's int i = 2 = b(2),it will eliminate b(2) and multiply
b.get(0)*b.get(1) = 1*3
I tried but it's not what i wanted
1*3
1*6
3*1
3*6
6*1
6*3
code
ArrayList<Integer> b = new ArrayList<Integer>();
b.add(1);
b.add(3);
b.add(6);
for(int i = 0; i < b.size(); i++) {
for(int j = 0; j < b.size(); j++) {
if(b.get(i) != b.get(j)) {
System.out.println(b.get(i) + "*" + b.get(j));
}
}
}
By doing this
for(int i = 0; i < b.size(); i++) {
for(int j = i+1; j < b.size(); j++) {
if(b.get(i) != b.get(j)) {
System.out.println(b.get(i) + "*" + b.get(j));
}
}
}
I will get output of
1*3
1*6
3*6
which is wrong.
Desired output
3*6
1*6
1*3