top of page
Writer's pictureRahul Kumar

Number Pattern 1

Print the following pattern

Pattern for N = 4

1 23 345 4567
Input Format :
N (Total no. of rows)
Output Format :
Pattern in N lines
Sample Input 1 :
3
Sample Output 1 :
1
23
345

Solution:




import java.util.Scanner;
public class Solution {


    public static void main(String[] args) {
        
        /* Your class should be named Solution.
        * Read input as specified in the question.
        * Print output as specified in the question.
        */
       
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int num = 1;
        
        while (num <= n){
            int j = 1; 
            int s = num;
            while (j <= num){
                System.out.print(s); 
                s = s+1;
                j = j+1;
                
            }
            System.out.println();
           num = num+1;
        }
        
    }

}








Recent Posts

See All

Comments


bottom of page