# Help!!

• 02-10-2001, 03:03 PM
Lindsey
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
• 02-10-2001, 06:18 PM
Kyle Gabhart
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

• 02-11-2001, 11:19 AM
lindsey
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....

• 02-11-2001, 02:33 PM
Kyle Gabhart
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