Write a program in java to print this pattern
Answers
Solution.
The given problem is solved using - Java.
public class Pattern{
public static void main(String s[]){
int n=6,i,j;
for(i=1;i<=2 * n-1;i++){
if(i<=n){
for(j=n;j>=i;j--)
System.out.print("* ");
System.out.println();
}
else{
for(j=1;j<=i-n+1;j++)
System.out.print("* ");
System.out.println();
}
}
}
}
Output.
* * * * * *
* * * * *
* * * *
* * *
* *
*
* *
* * *
* * * *
* * * * *
* * * * * *
See attachment for verification.
[tex][/tex]
Answer:
Program:-
public class Main
{
public static void main(String args[])
{
System.out.println("The pattern:");
for(int i=1;i<=5;i++)
{
for(int j=6;j>=i;j--)
{
System.out.print("*"+" ");
}
System.out.println();
}
for(int i=1;i<=6;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print("*"+" ");
}
System.out.println();
}
}
}