Print Right Triangle Number Pattern Type 4

PRINT PATTERN  3 44 555 6666

For any input number N Print the following code – For below code N=4

3
44
555
6666

PREREQUISITE:

Basic knowledge in Java programming, usage of loops.

ALGORITHM:

  1. Take input from user i.e number of lines required (N value) and take initial value a
  2. Take two loops one for each line (say ‘i’) and other for each digit in a particular line (say ‘j’). i starts from 1 and j starts from 1.
  3. Here ‘i’ loop is used to access each line from 1 to n and ‘j’ loop is used to print values in each line. j loop is executed until it reaches i value.
  4. Print ‘a’ value and   until the j loop reaches i value.
  5. Print the final value ‘a’ of each line and go to next line, increment a value.
  6. Repeat the ‘i’ loop until it reaches n.

CODE IN JAVA:

[code language=”java”]
import java.lang.*;
import java.io.*;
class Pattern
{
public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,i,j,a,t;
System.out.print("Enter N value:");
n=Integer.parseInt(br.readLine());
System.out.print("Enter initial Value:");
a=Integer.parseInt(br.readLine());
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(a);
}
System.out.println();
a++;
}
}
}
[/code]

 

TAKING INPUT:

DISPLAYING THE OUTPUT: