Search code examples
javamultiplicationlookup-tables

How to write a multiplications table in Java?


I'm learning Java and one of the task I've been given is to code a multiplication table that show like this:

 1  2  3  4  5  6  7  8  9 10 // 1
 2  4  6  8 10 12 14 16 18 20 // 2
 3  6  9 12 15 18 21 24 27 30 // 3
....

I'm working on it since 2 days but I can't put my finger on the answer. My main concern is how to write a code that does the multiplication to 10 and goes back to the next line for the next row.

I've tested a lot of approaches like the code below but there's a problem and I don't know where.

Please, help me.

int t = 1;
while(t <= 10) {
    int r = 1;
    int a = 1;
    int b = 1;
    System.out.print(r + " ");
    a = a + 1;
    t++;
}

Solution

  • is this wat yoy need

      public class HelloWorld{
    
         public static void main(String []args){
            System.out.println("Hello World");
            int count = 1;
    do {
      for( int j = 1; j <= 10; j ++) {
    System.out.print( count*j +""+'\t');}
                count++;
                System.out.print('\n');
    
    }while (count<11);
    
    
    
    
    
         }
    }