[quote=entanglement]Que jabulani está acontecendo aqui? Cadê “a”, “b” e o vetor destino ?
cont += cont[i] + cont[j] // cadê a, b e o vetor destino?
[/quote]
rs…desculpe, mas eu ri!
Cotonety…ve se te ajuda…
public static void main(String[] args) {
List<Integer> a = new ArrayList<Integer>();
a.add(1);
a.add(2);
a.add(3);
List<Integer> b = new ArrayList<Integer>();
b.add(4);
b.add(5);
b.add(6);
b.add(7);
int size = 0;
//Desta forma, o laço se restringe a lista de menor tamanho
if(a.size() > b.size()) {
size = b.size();
} else {
size = a.size();
}
for(int x = 0; x < size; x++) {
System.out.println("Indice [" + x + "] com valor: [" + (a.get(x) + b.get(x)) + "].");
}
}
Isto pode ser melhorado 100%…mas para entender está suficiente, certo?
int[] a = { 1, 2, 3, 4, 5 };
int[] b = { 6, 7, 8, 9, 10 };
int[] c;
if(a.length == b.length){
c = new int[b.length];
}else{
throw new ArrayIndexOutOfBoundsException("Os arrays devem possuir o mesmo número de parâmetros");
}
for (int i = 0; i < c.length; i++) {
c[i] = a[i] + b[i];
}
System.out.println(Arrays.toString(c));
Acho que assim resolve,
Agora tenta fazer esse exemplo usando ArraysList.