Created
June 19, 2019 15:25
-
-
Save hadihammurabi/f51c209b0fb3f0d393a731d75800c573 to your computer and use it in GitHub Desktop.
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
import java.util.Scanner; | |
public class SegitigaBintang { | |
public static void main(String[] args) { | |
System.out.print("Mau berapa bintang? "); | |
Scanner scanner = new Scanner(System.in); | |
int bintang = scanner.nextInt(); | |
// int bintang = 5; | |
for (int i = bintang; i > 0; i--) { | |
for (int j = bintang - i; j >= 0; j--) { | |
System.out.print(" "); | |
} | |
for (int j = 0; j < i; j++) { | |
if (i == bintang) | |
System.out.print("*"); | |
else { | |
if (j == 0) | |
System.out.print("*"); | |
else | |
System.out.print(" "); | |
} | |
} | |
for (int j = 0; j < i - 1; j++) { | |
if (i == bintang) | |
System.out.print("*"); | |
else { | |
if (j == i - 2) | |
System.out.print("*"); | |
else | |
System.out.print(" "); | |
} | |
} | |
System.out.println(""); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Segitiga Bintang Menjungkir