Pada kali ini ada 3 jenis segitiga yang akan saya bahas dengan bahasa pemograman Java.
1. Segitiga siku-siku terbalik
2. Segitiga siku-siku berbalik kanan
/*
* @ AFIF HIDAYATULLAH
* @ 201443501579
* @ S2K
* @ TUGAS PEMOGRAMAN
*/
import java.util.Scanner;
public class hitung
{
public static void main(String[] args) {
Scanner o = new Scanner (System.in);
int a, b, c,d,e,f,afif, ok, hiday, tullah ;
do
{
System.out.println("=========================================");
System.out.println("= POWERED BY AFIF =");
System.out.println("= segitiga siku siku =");
System.out.println("= pilih =");
System.out.println("= 1. segitiga siku terbalik kiri =");
System.out.println("= 2. segitiga siku berbalik kanan =");
System.out.println("= 3. exit =");
System.out.println("= =");
System.out.println("=========================================");
System.out.print("++++++masukuan pilihan =");
hiday = o.nextInt();
// OUTPUT :
// =========================================
// = POWERED BY AFIF =
// = segitiga siku siku =
// = pilih =
// = 1. segitiga siku terbalik kiri =
// = 2. segitiga siku berbalik kanan =
// = 3. exit =
// = =
// =========================================
// ++++++masukuan pilihan =
switch(hiday)
{
case 1:
System.out.println("=========================================");
System.out.println("= POWERED BY AFIF =");
System.out.println("= segitiga siku terbalik kiri =");
System.out.println("=========================================");
System.out.print("masukan batas jumlah segitiga =");
afif = o.nextInt();
for (a=1; a<=afif; a++) {
for (b=a ; bafif ; b++) {
System.out.print("*");
}
System.out.println("");
}
break;
// OUTPUT :
// =========================================
// = POWERED BY AFIF =
// = segitiga siku siku =
// = pilih =
// = 1. segitiga siku terbalik kiri =
// = 2. segitiga siku berbalik kanan =
// = 3. exit =
// = =
// =========================================
// ++++++masukuan pilihan =1
// =========================================
// = POWERED BY AFIF =
// = segitiga siku terbalik kiri =
// =========================================
// masukan batas jumlah segitiga =15
// ***************
// **************
// *************
// ************
// ***********
// **********
// *********
// ********
// *******
// ******
// *****
// ****
// ***
// **
// *
case 2:
System.out.println("=========================================");
System.out.println("= POWERED BY AFIF =");
System.out.println("= segitiga siku berbalik kanan =");
System.out.println("=========================================");
System.out.print("masukan batas jumlah segitiga =");
ok = o.nextInt();
System.out.print("\n");
for (int i = 1; i <= ok; i++) {
for(int j = i; j <= ok; j++)
System.out.print(" ");
for(int j = i; j >=1; j--)
System.out.print("*");
System.out.println();
}
break;
// OUTPUT :
// =========================================
// = POWERED BY AFIF =
// = segitiga siku siku =
// = pilih =
// = 1. segitiga siku terbalik kiri =
// = 2. segitiga siku berbalik kanan =
// = 3. exit =
// = =
// =========================================
// ++++++masukuan pilihan =2
// =========================================
// = POWERED BY AFIF =
// = segitiga siku berbalik kanan =
// =========================================
// masukan batas jumlah segitiga =15
// *
// **
// ***
// ****
// *****
// ******
// *******
// ********
// *********
// **********
// ***********
// ************
// *************
// **************
// ***************
case 3:
System.exit(0);
break;
// JIKA MEMILIH CASE 3 MAKA RUNING UOTPUTNYA OTOMATIS DISELESAIKAN(BERHENTI)/KELUAR
default: System.out.println("salah bro hanya 1 - 4");
break;
}
} while(true);
}
}
Belum ada tanggapan untuk "Cara membuat program segitiga siku siku dengan java"
Post a Comment