Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program that displays " 6 times" table

 
Timothy Willis
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm very new to java and programming.

Using a for loop i want to write a program that displays a "6 times" multiplication table; something like this:

1 x 6 = 6
2 x 6 = 12
3 x 6 = 18
.............
.............
12 x 6 = 72


Can anyone show me how to do this please? Thanks.
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, we try not to "show" you how to do it as much as get you to figure it out. First off, what is a for loop? What values do you want it to loop through? What do you want to do with these values?
If you have a firm understanding of the for loop, this program is pretty simple.
 
Lou Bassett
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A FOR loop has an iterator variable- something that gets incremented each time through the loop (ie. 1,2,3 ...). Think about using it in the body of the code to help you out.
 
Maureen Charlton
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following code will display the 2's, 3's 4's and 5's.

Hope this is a good example for you to build on.

public class Repetition
{
public static void main(String [ ] args)
{
int table, multiplier;

for (table = 2; table<5; table++)
{
//Print out the heading
System.out.println("\nMultiplication table for : "
+ table + " 's");
for(multiplier = 1; multiplier<=10; multiplier++)
{
System.out.print( (multiplier * table) + " \t");
}

}
System.out.println("\nLoops finished\n")
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic