Created
September 15, 2015 10:39
-
-
Save aviaryan/f4da6dc25c5680c44e03 to your computer and use it in GitHub Desktop.
Diamond shape generator Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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