Computer Science, asked by jthnk, 1 year ago

write a java programming to print sequence using to class?
output
=======
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Answers

Answered by Ankit0
0
import java.io.*
class Pattern
{
       public void main()
          {
                for(int i=1;i<=5;i++)
                 {
                         for(int j=1;j<=i;j++)
                            System.out.println(j);
                           System.out.println()
                   }
           }
}
Answered by anindyaadhikari13
1

Question:-

Write a Java program to print the following pattern.

1

12

123

1234

12345

Program:-

import java.util.*;

class Pattern

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of rows for the pattern: ");

int n=sc.nextInt();

for(int i=1;i<=n;i++)

{

for(int j=1;j<=i;j++)

System.out.print(j+" ");

System.out.println();

}

}

}

Take the input from the user and you will get the output.

Similar questions