Tutorial Programming dan Informasi Teknologi

January 14, 2017

Tutorial Membuat Pola Segitiga siku dengan Looping

Output

 /**  
  *   
  */  
 package latihan;  
 import java.util.Scanner;  
 /**  
  * Created by Muhamad Huda Avianto   
  * Jan 14, 2017  
  */  
 public class LatihanFor1 {  
      public static void main (String [] args){  
           Scanner scan = new Scanner(System.in);  
           System.out.println("masukan nilai : ");  
           int nilai = scan.nextInt();  
           LatihanFor1 ax = new LatihanFor1();  
           ax.pola(nilai);  
      }  
      public void pola(int n){  
           for(int i=0;i<=n;i++){  
                for(int j=0;j<=n;j++){  
                     if(i>j){  
                          System.out.print("*");  
                          }else{  
                               System.out.print(" ");  
                          }  
                }  
                System.out.println();  
           }  
      }  
 }  

No comments:

Post a Comment

Contact Form

Name

Email *

Message *