Results 1 to 4 of 4
  1. #1
    abatakji74 is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default Need help getting started on a lab!

    Hi guys here is my prompt:

    In this lab you are to write a simple Java program to prompt the user for two 3-digit integers and print the
    product of the two integers in the following form. There is a sample program in directory
    ~wang/sample20.

    123
    X 246
    -------------------
    738
    492
    246
    -------------------
    30258

    So far, I have came up with using a scanner assigned to two variables to get the 2 integers. But now Im stuck on how I come up with the work in progress under it. Such as the numbers 738, 492, 246. The whole problem is supposed to come out in the output. So any help would be appreciated. Thanks

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    It's a good idea to preserve indents by using the "code" tags. You put [CODE] at the start of the bit that needs special treatment and [/CODE] at the end. (Of course the major use for this is when you are posting code...)

    Java Code:
                                           
      123 
    X  246 
     -------------------
                  738 
                492 
             246 
     -------------------
             30258

    Is this how it's supposed to look? It's your question, but I would have though something more along the lines of

    Java Code:
                                           
           123 
    X      246 
     -------------------
           738 
          492 
         246 
     -------------------
         30258
    ------------------------------------

    One step at a time, of course. It would be best put the formatting aside and concentrate on what sunde suggests: describe in plain words how you would get those three numbers, then try to write code for that.
    Last edited by pbrockway2; 01-30-2011 at 01:06 AM.

  3. #3
    abatakji74 is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Well sunde887 I was thinking about how I would do it in english... How would I set it up to work one digit of each 3 digit integer at a time? I can do if statements to add on to the next equation if one of them is more than 9. Thanks pbrockway2, Im new to these forums so I wasnt sure how to display it correctly. Im supposed to use System.out.printf() to format how the equation looks.

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    You can either convert the number into a String and then a char[], or split the number into digits by using division and the remainder operator (%). I think the latter approach makes more sense. Then you need to figure out how to pad each line of output with leading spaces to make it all line up nicely. You should probably write a helper method to do that part.

    -Gary-

Similar Threads

  1. Getting Started Help (:
    By Jcbconway in forum AWT / Swing
    Replies: 3
    Last Post: 10-10-2010, 07:52 AM
  2. Help me get started
    By shanky in forum Java Servlet
    Replies: 2
    Last Post: 05-02-2010, 03:37 PM
  3. How do I get started?
    By programmer-in-training in forum New To Java
    Replies: 4
    Last Post: 01-11-2008, 07:45 AM
  4. Getting Started
    By Doorsmaniac in forum Java Applets
    Replies: 0
    Last Post: 11-24-2007, 03:40 AM
  5. I need help getting started
    By Android in forum New To Java
    Replies: 2
    Last Post: 10-30-2007, 04:46 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
  •