Results 1 to 11 of 11
  1. #1
    dakid2 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default 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. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by dakid2 View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    dakid2 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    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. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by dakid2 View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    dakid2 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

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

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by dakid2 View Post
    I'm having trouble with writing the loop.
    Thanks for your help. I will post my question in a javascript forum.
    I think I can answer your question:

    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
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    dakid2 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Talking

    Jos,
    Thanks that worked. :)

  8. #8
    dakid2 is offline Member
    Join Date
    Mar 2011
    Posts
    5
    Rep Power
    0

    Default

    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. #9
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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. #10
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,415
    Rep Power
    20

    Default

    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. #11
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Quote Originally Posted by Darryl.Burke View Post
    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.

Similar Threads

  1. Multiplication Table
    By BillyB in forum New To Java
    Replies: 17
    Last Post: 12-24-2010, 06:58 AM
  2. need help with this: multiplication table
    By MsIceCold in forum New To Java
    Replies: 7
    Last Post: 07-13-2010, 01:31 PM
  3. Problem regarding multiplication
    By javanewbie1234 in forum New To Java
    Replies: 1
    Last Post: 03-10-2010, 09:27 AM
  4. Help with Multiplication
    By phil028 in forum New To Java
    Replies: 1
    Last Post: 12-06-2007, 07:39 PM
  5. Help with multiplication table
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 04:44 PM

Posting Permissions

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