Write a Java program to print the following pattern
12345
2345
345
45
5
45
345
2345
12345
Answers
Answered by
0
Answer:
First, let us begin with the basic and the commonly asked pattern program in Java i.e Pyramid.
1. Pyramid Program
*
* *
* * *
* * * *
* * * * *
Let’s write the java code to understand this pattern better.
public class Edureka
{
public static void pyramidPattern(int n)
{
for (int i=0; i<n; i++) //outer loop for number of rows(n) { for (int j=n-i; j>1; j--) //inner loop for spaces
{
System.out.print(" "); //print space
}
for (int j=0; j<=i; j++ ) //inner loop for number of columns
{
System.out.print("* "); //print star
}
System.out.println(); //ending line after each row
}
}
public static void main(String args[]) //driver function
{
int n = 5;
pyramidPattern(n);
}
}
2. Right Triangle Star Pattern
*
* *
* * *
* * * *
* * * * *
Similar questions