DEV Community

Vasanth S
Vasanth S

Posted on

Diamond Pattern in java;

Today, I had learned the topic in patterns that is diamond pattern

the output looks like,
The rows=7;

   * 
  * * 
 * * * 
* * * * 
Enter fullscreen mode Exit fullscreen mode






* * * * 
 * * *
  * * 
   * 
Enter fullscreen mode Exit fullscreen mode

The code in java for above output of diamond pattern is

public class diamond {
public static void main(String[] args) {
int row =7;
for(int i=0;i<row;i++){
for(int j=0;j<row-i;j++){
System.out.print(" ");
}
for(int k=0;k<i+1;k++){
System.out.print("* ");
}
System.out.println();
}
for(int i=0;i<row;i++){
for(int j=0;j<i+1;j++){
System.out.print(" ");
}
for (int k=0;k<row-i;k++){
System.out.print("* ");
}
System.out.println();
}

}
Enter fullscreen mode Exit fullscreen mode

}

java #pattern #javaprograms #diamondpattern #diamond

Top comments (0)