Ask agar bentuknya tetap walau di ganti nilai variabelnya ??

Discussion in 'Programming' started by giovani, Aug 19, 2015.

  1. giovani

    giovani Member

    Joined:
    Apr 29, 2015
    Messages:
    343
    Likes Received:
    10
    Trophy Points:
    18
    [​IMG]

    jadi saya ada masalah kalau itu int angka di rubah nilainya bentuknya jadi berubah.. itu awalnya int angka bernilai 9; bentuknya seperti ketupat,, tapi setelah saya rubah nilainya.. bentuknya pun berubah.. ada cara tidak untuk membuat bentuknya tetap,, saya sudah coba pakai fungsi IF.. tapi blm ketemu,, mungkin teman teman bisa membantu..

    SCRIPT:
    public class tigasatu {
    public static void main(String[] args){
    int angka = 9;

    for (int a=angka-4; a>1; a--){
    for (int b=1; b<=angka; b++ ){
    if (b == a||b==(angka-a)+1){
    System.out.print("*");
    }else{
    System.out.print(" ");

    }
    }
    System.out.println();

    }

    for (int b=1; b<=angka-4; b++ ){
    for (int a=angka; a>=1; a--){
    if (b == a||b==(angka-a)+1){
    System.out.print("*");
    }else{
    System.out.print(" ");

    }
    }
    System.out.println();

    }
    }
    }
     
  2. giovani

    giovani Member

    Joined:
    Apr 29, 2015
    Messages:
    343
    Likes Received:
    10
    Trophy Points:
    18
    gak ada respon *badluck**boohoo**mati* .....
     
  3. asli3rut

    asli3rut Member

    Joined:
    Sep 6, 2014
    Messages:
    641
    Likes Received:
    44
    Trophy Points:
    28
    Agan geovani mungkin agan coba script java berikut ini, sedikit berbeda namun dinamis:
    Agan bisa masukan angka berapa saja untuk membuat ketupat, namun harus bilangan ganjil, agar simetris

    CODE:

    public class tigasatu {

    public static void main(String[] args) {

    int angka = 15; //silahkan ganti dengan bilangan ganjil sesuka hati

    int h = ((int) angka / 2) + 1;
    int mark1 = h;
    int mark2 = h;
    for (int i = 1; i <= angka; i++) {
    String s = "";
    for (int j = 1; j <= angka; j++) {
    if (j == mark1 || j == mark2) {
    s += "*";
    } else {
    s += " ";
    }
    }
    System.out.println(s);
    if (i < h) {
    mark1--;
    mark2++;
    } else {
    mark1++;
    mark2--;
    }

    }
    }
    }
     
    benjaminfrankline likes this.
  4. mario00

    mario00 New Member

    Joined:
    Aug 20, 2015
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    hebat bener nih master coding yang satu ini
    kapan-kapan kalau aku ada tugas kampus untuk bikin coding, tolong ajarin ya master *wow3*
     
  5. giovani

    giovani Member

    Joined:
    Apr 29, 2015
    Messages:
    343
    Likes Received:
    10
    Trophy Points:
    18
    keren bang,, penjelasanya dong bang,, hehehehe
     
  6. yanuarfikri

    yanuarfikri Member

    Joined:
    Nov 22, 2015
    Messages:
    23
    Likes Received:
    13
    Trophy Points:
    8
    ikutan nyimak dech gan
     
Loading...

Share This Page