# Need help getting started on a lab!

• 01-30-2011, 01:55 AM
abatakji74
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
• 01-30-2011, 02:01 AM
pbrockway2
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...)

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

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.
• 01-30-2011, 02:05 AM
abatakji74
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.
• 01-30-2011, 02:30 AM
gcalvin
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-