Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

Pattern problems : Write a Java program to print different character on each line and having character increment with each line.

Program to Pattern problems : Write a Java program to print different character on each line and having character increment with each line. As shown below :

1
22
333
4444
55555
666666



package com.hubberspot.patterns.problems;

import java.util.Scanner;

public class MultipleLineDifferentPattern {

    public static void main(String[] args) {

        int pattern;
        int noOfTimes;

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the start number to print : ");
        pattern = scanner.nextInt();

        System.out.print("Enter number of times it should get printed : ");
        noOfTimes = scanner.nextInt();

        for(int i = 1; i <= noOfTimes; i++) {

            for(int j = 1; j <= i; j++) { 
                System.out.print(pattern);
            }
            System.out.println();
            pattern++;
        }
    }
}


Output of the program : 

 
 
© 2021 Learn Java by Examples Template by Hubberspot