Printing and Loops

Collapse Content

Now that you know how to print, you can really demonstrate the power of loops.

You will be given two numbers, a and b. Print a (the first number) b times. For example, if given 3 and 5, you should print 3 5 times: 33333.

Print each case on one line. Remember to use System.out.print to print without adding a newline.

Note: For more practice, try solving printing multiplication.


Print each number a b times.

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.


  • How many possible solutions are there to this challenge?

  • There are many possible ways, but one way is particularly straightforward.

  • This code fragment also works:
    for(int x = 1; x <= b; x++)

  • yo keesh can anyone post the answer...

  • import java.util.Scanner;
    public class PrintLoop
    public static void main(String[] args)
    int a;
    int b;
    Scanner input = new Scanner(;

  • for(int c = b; c > 0; c = c - 1)

  • import java.util.Scanner;

    public class Loop1{
    public static void main(String args[]){
    Scanner input1 = new Scanner(;
    System.out.println("Enter First number !");

  • import java.util.Scanner;
    public class Main(){
    public static void main(String[] args){
    int a=2;
    int b=4;
    for(int i=1;i<=b;i=i+1){

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