Shortest, kita serius banget lho ngerjain ini tugas. Sampek ada acara nginep bersama segala buat nyeleseinnya. Subhanallah sekali kan. Walaupun hasil nginepnya tetep nihil sih, at the end ujung-ujungnya ngopi program temen trus kita adakan proses editing. Bwahaha. And then, beginilah hasilnya. Taraaa...
Program membuat segi enam bintang
Tugas1.java
/*
* Program membuat segi enam bintang
* by Disma Ariyanti Widodo
* by Fatonah Dwi Putri
* by Soraya Mir'atun Miswah
*/
package kelompok; //opsional, sesuai package yang digunakan
//untuk memanggil class Scanner
import java.util.Scanner;
//nama class
public class Tugas1 {
public static void main(String[] args) {
//user menginputkan angka untuk menentukan jumlah bintang yg akan ditampilkan
System.out.print("Masukan angka : ");
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = a;
int c = a;
int d = 1;
for (int i = 0; i < a - 1; i++) {
System.out.print(" ");
}
for (int i = 0; i < a; i++) {
System.out.print("*");
}
System.out.println("");
for (int i = 0; i < b - 1; i++) {
for (int j = 0; j < c - 2; j++) {
System.out.print(" ");
}
System.out.print("*");
for (int j = 0; j < a; j++) {
System.out.print(" ");
}
a = a + 2;
System.out.print("*");
System.out.println("");
c--;
}
for (int i = 0; i < b - 2; i++) {
for (int j = 0; j < d; j++) {
System.out.print(" ");
}
System.out.print("*");
for (int j = 0; j < a - 4; j++) {
System.out.print(" ");
}
a = a - 2;
System.out.print("*");
System.out.println("");
d++;
}
for (int i = 0; i < b-1; i++) {
System.out.print(" ");
}
for (int i = 0; i < b; i++) {
System.out.print("*");
}
System.out.println("");
}
}
Output :
Program Segi Enam Bintang |
0 Comments