Kamis, 05 Mei 2011

Bintang 3 & 4

 -Inputan Bintang_3-

import javax.swing.*;
public class tugas_bintang3 {
public static void main (String [] args){
    int baris,x,y;
    baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
    x=baris+1;
    for(int i=1;i<=baris;i++){
        for (int j=1;j<=baris;j++){
            y=i+j;
            if (x<=y)
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
        }
    }

}


-Output-
     *
   **
  ***
****



-Input Bintang_4-

import javax.swing.*;
public class tugas_bintang4 {
public static void main (String [] args){
    int baris;
    baris=Integer.valueOf(JOptionPane.showInputDialog("Masukan banyak bintang?"));
    for(int i=1;i<=baris;i++){
        for (int j=1;j<=baris;j++){
            if (i<=j)
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
        }
    }

}



-Output-
****
 ***
  **
   *

Tidak ada komentar:

Posting Komentar

chatme


ShoutMix chat widget