# Thread: need help with multiplication

1. Member
Join Date
Mar 2011
Posts
5
Rep Power
0

## 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.

2. 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

3. Member
Join Date
Mar 2011
Posts
5
Rep Power
0
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>");
}

4. 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

5. Member
Join Date
Mar 2011
Posts
5
Rep Power
0
I'm having trouble with writing the loop.
Thanks for your help. I will post my question in a javascript forum.

6. 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.

Java 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

7. Member
Join Date
Mar 2011
Posts
5
Rep Power
0
Jos,
Thanks that worked. :)

8. Member
Join Date
Mar 2011
Posts
5
Rep Power
0
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);
}

9. 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.

10. 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

11. 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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•