-2
The circumstances are in the code that works:
String[][] compras = new String[][] { { "item 1", "1.70" }, { "item 2", "39.90" }, { "item 3", "9.90" }, { "item 4", "4.90" }, { "item 5", "7.90" } };
int soma = 0;
for (int i = 0; i < compras.length; i++) {
for (int j = 0; j < compras[i].length; j++) {
if (j == 1) {
soma = (int) (soma + Double.parseDouble(compras[i][j]));
}
}
}
System.out.println("Total das compras: R$ " + soma);
}
Important when posting a question, explain objectively and punctually the difficulty found, accompanied by a [mcve] problem and attempt to solve. To understand what kind of question serves the site and, consequently, avoid closures and negativities worth reading What is the Stack Overflow and the Stack Overflow Survival Guide (summarized) in Portuguese.
– Bacco
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero