#Making a multiplication table without using any loops

1 messages Β· Page 1 of 1 (latest)

viscid berry
#

So im new to java and have a little task to write a multiplication table but cant use any loops.

chilly boltBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question πŸ€–. Maybe it helps! In any case, a human is on the way πŸ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

If you want to create a multiplication table without using any loops, you can use recursion instead. Here's an example of how you can achieve this:

public class MultiplicationTable {
    public static void main(String[] args) {
        printMultiplicationTable(1, 1);
    }

    public static void printMultiplicationTable(int row, int col) {
        if (row <= 10) {
            if (col <= 10) {
                System.out.printf("%4d", row * col);
                printMultiplicationTable(row, col + 1);
            } else {
                System.out.println();
                printMultiplicationTable(row + 1, 1);
            }
        }
    }
}

In this example, the printMultiplicationTable method is called recursively to print each element of the multiplication table. The row and col parameters represent the current row and column numbers.

The base case for recursion is when row becomes greater than 10. At that point, the method stops calling itself and the program terminates.

Note that this approach is not recommended for large multiplication tables as it may lead to a StackOverflowError due to excessive recursion.

grand shuttle
#

I hope the chatgpt answer helps?

ashen bay
gilded sinew
#

or streams

#

They didn't state not to use implicit loops πŸ˜„

grand shuttle
gilded sinew
#

I mean, it's not specified? πŸ˜„

viscid berry
#

this was the task

ashen bay