dimanche 28 mai 2017

Java Using For Loop while handling Array to make Pattern

If I want to print the pattern below, and I have an Array:

*******
 ***** 
  ***  
   *   
  ***  
 ***** 
*******

This is what I have so far:

public static void main(String[] args)
{

int[] p = {7,5,3,1,3,5,7};

for(int i=0; i<=7; i++)
{

System.out.print("\n");

for(int k =i; k<=7; k++)
{

 k = p[i];  //I'm trying to find a way to print "*"s with array element value 



for(int j = i; j<=7; j++)
 {
System.out.print("*");
 }
}
}
}
}

I definitely went wrong somewhere, and I apologize for my ignorant. I'm just trying to learn. Thanks!

Aucun commentaire:

Enregistrer un commentaire