Printing and Loop Practice

Collapse Content

You are the programmer in charge of the multiplication table team. You will be given two numbers, a and b. Can you print all the multiples of a from a through a*b? Please them on one line, separated by spaces.


Print the numbers from a through a*b.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.


  • I am getting runtime error everytime System.out.println(); is being executed.

  • @David, your code looks like it runs ok. How would you print the next different multiple of a each time, when you have an index i that increases each time?

  • Hi, thanks for the answer. The runtime error was showing up before I clicked reset, seems it cached some error? Anyway great work this website.

  • Can you tell me what I've done wrong in the code below:

    For (int index=a, index=<b, int index = index + 1){

  • To fix the syntax errors, replace =< with <= and remove the second int since you've already declared index as an int in the beginning. You can click on the buttons on the side for help with syntax.

  • if someone is looking for some other solution here is mine and it includes 1 if:

    public static void doStuff(int a, int b){
        for (int i=a;i<=a*b;i=i+1){
            if (i%a==0){
            System.out.print(i + " ");

    public class Main {

    public static void doStuff(int a, int b){
    for(int i=1; i<=b ; i=i+1){
    System.out.print(" "+ a*i);
  • I am constantly getting the following runtime errors: error: class, interface, or enum expected
    public static void main(String[] args) {

  • @Joshua, careful with {}. Reset the code and put back code in the method body.

  • What development app should I use to try this on my own? NetBeans? I've heard of that one...

  • In the next module, we suggest beginners use BlueJ to get started. Afterwards, you can use any of the main IDEs (Netbeans, Eclipse or IntelliJ)

  • Why do we have to put the print statement for the space on a separate line? I had no luck with (m, ' ')

Contact Us
Sign in or email us at [email protected]