import java.util.Scanner; public class bangundatar { public static void main (String args[]){ Scanner input=new Scanner(System.in); System.out.print ("Masukan Tinggi segitiga : "); int batas = input.nextInt(); //segitiga siku-siku biasa System.out.println("Segitiga siku-siku Biasa"); for(int i=1;i<=batas;i++){//tinggi for(int j=1;j<=i;j++){ //perulangan kesamping System.out.print("* "); } System.out.println(); } System.out.println(); //Segitiga siku-siku Terbalik System.out.println("Segitiga siku-siku terbalik"); for(int i=1;i<=batas;i++){ //tinggi for(int j=batas;j>=i;j--){ //perulangan kesamping System.out.print("* "); } System.out.println(); } System.out.println(); //segitiga piramid System.out.println("Segitiga Biasa"); for(int i=1;i<=batas;i++){//tinggi for(int j=batas;j>=i;j--){ //spasi System.out.print(" "); } for(int k=1;k<=i;k++){ System.out.print("* "); } System.out.println(); } System.out.println(); //segitiga piramid terbalik System.out.println("Segitiga Biasa Terbalik"); for(int i=1; i<=batas; i++){//tinggi for(int j=1;j<=i;j++) { //karakter spasi System.out.print(" "); } for(int k=batas;k>=i;k--){ System.out.print("* "); } System.out.println(); } System.out.println(); //Jajar genjang System.out.println("Jajargenjang"); for(int i=1; i<=batas; i++){//tinggi for(int j=1;j<=i;j++) { //karakter spasi System.out.print(" "); } for(int k=batas;k>=1;k--){ System.out.print("* "); } System.out.println(); } //Belah ketupat System.out.println("Belahketupat"); for(int i=1;i<=batas;i++){//tinggi for(int j=batas;j>=i;j--){ //spasi System.out.print(" "); } for(int k=1;k<=i;k++){ System.out.print("* "); } System.out.println(); } for(int i=1; i<=batas; i++){//tinggi for(int j=1;j<=i+1;j++) { //karakter spasi System.out.print(" "); } for(int k=batas-1;k>=i;k--){ System.out.print("* "); } System.out.println(); } } }
Komentar
Posting Komentar