Skip to content

Instantly share code, notes, and snippets.

@hadihammurabi
Created June 19, 2019 15:25
Show Gist options
  • Save hadihammurabi/f51c209b0fb3f0d393a731d75800c573 to your computer and use it in GitHub Desktop.
Save hadihammurabi/f51c209b0fb3f0d393a731d75800c573 to your computer and use it in GitHub Desktop.
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("");
}
}
}
@hadihammurabi
Copy link
Author

Segitiga Bintang Menjungkir

Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment