Skip to content

Instantly share code, notes, and snippets.

@aslamanver
Last active August 31, 2019 13:04
Show Gist options
  • Save aslamanver/8a72e449a79ab4f61bd57c753a75d818 to your computer and use it in GitHub Desktop.
Save aslamanver/8a72e449a79ab4f61bd57c753a75d818 to your computer and use it in GitHub Desktop.
Print stars in "X" shape using Java
class Stars {
public static void main(String args[]) {
int p = 20, diff = 2;
for (int i = p, d = -diff; i <= p; i += d) {
while ((i == 0 && d != diff) || i == 1 && d != diff)d = diff;
for (int k = 0; k < (p - i) / 2; k++) System.out.print(" ");
for (int k = 0; k <= i; k++) System.out.print("*");
System.out.println(" ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment