DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Thread: Help!!

  1. #1
    Lindsey Guest

    Help!!


    Hi, I need some help with writing a multiplication table in Java. I am using
    two for loops to get started but I can't seem to get the right out put.
    I know this is a stupid question but I am a beginner and need help. Any
    suggestions would be appreciated.
    Sincerely,
    Lindsey

  2. #2
    Kyle Gabhart Guest

    Re: Help!!


    "Lindsey" <Zave4@aol.com> wrote:
    >
    >Hi, I need some help with writing a multiplication table in Java. I am

    using
    >two for loops to get started but I can't seem to get the right out put.


    >I know this is a stupid question but I am a beginner and need help. Any
    >suggestions would be appreciated.
    >Sincerely,
    >Lindsey


    Lindsey,

    If you will post the code you currently have and the output you're getting,
    then I would be happy to help steer you in the right direction.

    Cordially,

    Kyle Gabhart
    DevX Java Pro



  3. #3
    lindsey Guest

    Re: Help!!


    "Kyle Gabhart" <gabhart@usa.com> wrote:
    >
    >"Lindsey" <Zave4@aol.com> wrote:
    >>
    >>Hi, I need some help with writing a multiplication table in Java. I am

    >using
    >>two for loops to get started but I can't seem to get the right out put.

    >
    >>I know this is a stupid question but I am a beginner and need help. Any
    >>suggestions would be appreciated.
    >>Sincerely,
    >>Lindsey

    >
    >Lindsey,
    >
    >If you will post the code you currently have and the output you're getting,
    >then I would be happy to help steer you in the right direction.
    >
    >Cordially,
    >
    >Kyle Gabhart
    >DevX Java Pro
    >
    >


    for (int Num = 0; Num < Max2; Num ++){
    System.out.println (Num);
    Place++;
    Mult++;
    for (int Num2 = Num + 1; Num2 < Max; Num2 ++ ){
    System.out.print (Num2);
    if (Num2 >= Place)
    break;
    }
    }

    OUTPUT
    1234567891011121314151617181
    234567891011121314151617182
    34567891011121314151617183
    4567891011121314151617184
    567891011121314151617185
    67891011121314151617186
    7891011121314151617187
    891011121314151617188
    9101112131415161718

    What i want thee output to be

    123456789
    2468101214
    36912151821
    481620242832
    so on....





  4. #4
    Kyle Gabhart Guest

    Re: Help!!


    Lindsey,

    I think that you were just trying to make it too difficult. That seems to
    be a favorite tactic of all programmers. More often then not, there is a
    simpler solution. There's probably an even simpler way than what I came
    up with, but this code at least gives the output you're looking for:

    for ( int num = 1; num <= 9; num++ )
    {
    for ( int mult = 1; mult <= 9; mult++ )
    System.out.print( num*mult + " " );

    System.out.println();
    } //end for{}

    Essentially, the variable num iterates through the loop with values from
    1 to 9. Each iteration through the loop also iterates through the inner
    loop. This loop multiplies the variable num by the variable mult (num*mult).
    Thus we have 1*1, 1*2, 1*3, ... 1*9, in the first iteration through the
    loop. The next iteration does 2*1, 2*2... and so on.

    I hope this is helpful. If you have any more questions, don't hesitate to
    post it here or e-mail me directly.

    Happy Coding!

    Cordially,

    Kyle Gabhart
    DevX Java Pro


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links