Last active
August 31, 2019 13:04
-
-
Save aslamanver/8a72e449a79ab4f61bd57c753a75d818 to your computer and use it in GitHub Desktop.
Print stars in "X" shape using Java
This file contains 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
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