Question

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.

Was it helpful?

Solution

for (int index = 0; index < xpoints.length; index++) {
    double x = Double.parseDouble(xpoints[index]);
    double y = Double.parseDouble(ypoints[index]);

    sumnationxy += (x * y);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top