Skip to content

Instantly share code, notes, and snippets.

@aviaryan
Created September 15, 2015 10:39
Show Gist options
  • Save aviaryan/f4da6dc25c5680c44e03 to your computer and use it in GitHub Desktop.
Save aviaryan/f4da6dc25c5680c44e03 to your computer and use it in GitHub Desktop.
Diamond shape generator Java
package class1;
public class DiamondNegative {
public static void main(String [] args){
int sz = 11;
int i,j,k,l,r;
for (i=0; i<sz; i++) System.out.print("* ");
System.out.println();
for (i=0; i<sz-2; i++){
k = 2*i+1;
if (k > (sz-2))
k = sz + sz - k - 4;
l = sz/2-k/2;
r = sz/2+k/2;
for (j=0; j<sz; j++){
if (j >= l && j <= r)
System.out.print(" ");
else System.out.print("* ");
}
System.out.println();
}
for (i=0; i<sz; i++) System.out.print("* ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment