# need help with multiplication

• 03-06-2011, 06:46 PM
dakid2
need help with multiplication
I need to create a display that will create tables of multiplications for 2, 3, 4, 5, 6, 7, 8, and 9. using 2 for loops.

2X1=1
2x2=4
2x3=6
need it for each variable.
• 03-06-2011, 06:56 PM
JosAH
Quote:

Originally Posted by dakid2
I need to create a display that will create tables of multiplications for 2, 3, 4, 5, 6, 7, 8, and 9. using 2 for loops.

2X1=1
2x2=4
2x3=6
need it for each variable.

So you need to display the result of X, Y and XxY for each value of X and Y in the interval [1, 9]; that makes two (nested loops) alright and a couple of System.out.println() statements.

kind regards,

Jos
• 03-06-2011, 07:19 PM
dakid2
here is my code so far
var y = 1;
var x = 5;

for (y=1; y<11; y = y + 1){
sum = y * x;
document.write("<li>")
document.write ( y + " x " + x + " = " + sum + "<br>");
}
• 03-06-2011, 07:22 PM
JosAH
Quote:

Originally Posted by dakid2
here is my code so far
var y = 1;
var x = 5;

for (y=1; y<11; y = y + 1){
sum = y * x;
document.write("<li>")
document.write ( y + " x " + x + " = " + sum + "<br>");
}

Two remarks:

1) I don't see a nested loop: you need one for y and one for x;
2) that is Javascript and this is a Java forum.

kind regards,

Jos
• 03-06-2011, 07:40 PM
dakid2
I'm having trouble with writing the loop.
Thanks for your help. I will post my question in a javascript forum.
• 03-06-2011, 08:05 PM
JosAH
Quote:

Originally Posted by dakid2
I'm having trouble with writing the loop.
Thanks for your help. I will post my question in a javascript forum.

Code:

```var y; var x; var prod; for (y= 1; y<= 10; y++){   for (x= 1; x <= 10; x++) {       prod = y * x;       document.write("<li>")       document.write ( x + " x " + y + " = " + prod + "<br>");   } }```
this should work ...

kind regards,

Jos
• 03-06-2011, 09:42 PM
dakid2
Jos,
Thanks that worked. :)
• 03-08-2011, 03:00 AM
dakid2
Can you help me with this? I know its not javascript. I'm trying to write this code.

function sumThese() {
var sumEven=0, sum5=0;
for(i=0; i<100; i++) {
sumEven = (i % 2 == 0) ? parseInt(sumEven+i) : sumEven ; // if value of i modulus 2 is 0, gets all even numbers
sum5 = (i % 5 == 0) ? parseInt(sum5+i) : sum5 ; // if value of i modulus 5 is 0, gets all multiples of 5
}
alert("sumEven = " + sumEven + ", and sum5 = " + sum5);
}
• 03-08-2011, 03:05 AM
sunde887
Please make another thread, don't hijack old solved posts. When/if you make a new thread, please be sure to actually provide a concrete, detailed question.
• 03-08-2011, 04:37 AM
DarrylBurke
Actually, it's not a hijack. It's the same OP back with another JavaScript question.

@dakid2: Please find a JavaScript forum, this isn't one.

db
• 03-08-2011, 04:41 AM
sunde887
Quote:

Originally Posted by Darryl.Burke
Actually, it's not a hijack. It's the same OP back with another JavaScript question.

@dakid2: Please find a JavaScript forum, this isn't one.

db

lol, good job paying attention..apparently I wasn't paying enough attention.