Thursday, 29 December 2011

Pohon Natal dengan JAVA

Berhubung ini baru selesai natal.. saya ingin membuat pohon natal dengan Bahasa Pemrograman JAVA..

berikut kodingnya.

public class PohonNatal {
   public static void main (String[ ]args){
           for (int j=1; j<=4;j++){
    for (int k=11-0;k>=j+j;k--){System.out.print(" ");}
    for (int k=1;k<j;k++){ System.out.print("X ");}
 for (int k=1; k<=j;k++){ System.out.print("X ");}  
 System.out.println(" ");
}



          
           for (int j=1; j<=4;j++){
    for (int k=11-4;k>=j+j;k--){System.out.print(" ");}
    for (int k=1;k<j;k++){ System.out.print("X ");}
 for (int k=5; k<=j+8;k++){ System.out.print("X ");}  
 System.out.println(" ");
}
          
for (int j=1;j<=2;j++){
    for (int k=8;k>=0;k--){System.out.print(" ");}
    for (int k=1;k<=2;k++){
        System.out.print("H ");
    }
    System.out.println("");
}
   }
}


SELAMAT MENCOBA

No comments: