Write a program in Java to print the following pattern :-
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Answers
public class Main {
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; ++i) {
for (int j = 1; j <= i; ++j) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
/*
Project Type: Brainly Answer
Date Created: 21-02-2021
Date Edited Last Time: ---NIL---
Question Link: https://brainly.in/question/35383877
Question: Write a program in Java to print the following pattern :-
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program Created By: atrs7391
Programming Language: Java
Language version (When program created or last edited): jdk-15.0.2
*/
package Brainly_Answers.Program;
public class Pattern_3 {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j+" ");
}
System.out.println();
}
}
}