Write a java program to print this pattern
1
12
123
1234
12345
Answers
Answered by
100
int i, j;
for (i=1;i<=5;i++)
(
for (i=1;j<=i;j++)
system. outprint(" "+j);
system. outprint /n();
)
for (i=1;i<=5;i++)
(
for (i=1;j<=i;j++)
system. outprint(" "+j);
system. outprint /n();
)
Answered by
45
Below are the java program for the above question:
Explanation:
public class Series_12 // class definition
{
public static void main(String[] args) // main function
{
int size=5; // variable which holds the size of the series if this will changed then the size will changed.
for(int i=1;i<=size;i++) // first loop which is used to print the series up to size.
{
for(int j=1;j<=i;j++) // second loop which prints the one line elements.
{
System.out.print(j); // print the series
}
System.out.println(""); // for line change
}
}
}
Output:
The above program render the series which the question asked to render--
1 12 123 1234 12345. ( Here space means line change).
Code Explanation:
- The above code prints the series because the first loop tells the second loop that how many times it prints any line and the second loop will print every line of the series.
Learn More:
- Java: https://brainly.in/question/12215990
Similar questions
Math,
7 months ago
Science,
7 months ago
Geography,
1 year ago
Biology,
1 year ago
Social Sciences,
1 year ago