for (int index = 0; index < xpoints.length; index++) {
double x = Double.parseDouble(xpoints[index]);
double y = Double.parseDouble(ypoints[index]);
sumnationxy += (x * y);
}
Looping through 2 Arrays in 1 loop
-
13-07-2023 - |
Frage
I have been working on this one loop for too long and cannot figure it out. My program has 2 jtextareas named xpointsArea and ypointsArea and i need it to loop through both and get the sumnation of (x * y) for instance if i had 2,4,6 in the xArea and 5,3,2 in the yArea then it would mulitply 2 * 5, 4 * 3, 2 * 6 and then add the products so the answer would be 34.
Here is what i have: `
String[] xpoints = xpointsArea.getText().split("\\n");
String[] ypoints = ypointsArea.getText().split("\\n");
for (String xpoint : xpoints) {
double x = Double.parseDouble(xpoint);
double y = Double.parseDouble(ypoint);
sumnationxy += (x * y);
}`
I cannot figure out how to get the value of the ypoint without making a nested forloop which wouldnt work. Please help, thanks.
Lösung
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow