2014-03-19 55 views
1

我正在尝试创建一个循环,该循环将创建星号行,星号的数量等于INT数组。该循环将从索引0开始,直到数组结束。无法弄清楚如何对其进行编码。任何帮助表示赞赏。这就是我到目前为止所做的,而且我被困在接下来要做的事情上。基于Int数组打印星号

int e = 0; 
int[] yValuesInt = new int[yValues.length]; 
    for (z=0; z<yValues.length; z++) 
    { 
     yValuesInt[z] = (int) yValues[z]; // changing from double array to int 
    } 

    for (int i = 0; i<=arrayAmount-1; i++) // loop to continue until array is over 
    { 

    while (e<yValuesInt[z]) // loop that is creating asterisks based on int array 
     { 
      System.out.print("" + asterisk); 
      e++; 
     } 
     System.out.println(": " ); 
    } 

回答

0

我用我自己的代码,因为我不知道你的z变量是什么或arrayAmount变量等

这个概念是非常简单的,但是,我下面有一个小例子:

static int[] intArray = {5, 6, 10, 4}; 

public static void main(String[] args){ 
     for (int i = 0; i < intArray.length; i++){ // Iterate through the int array 
      for(int j = 0; j < intArray[i]; j++){ // loop intArray[i] times 
       System.out.print("" + "*"); 
      } 
      System.out.println(": " ); 
     } 
    } 

给出以下输出:

*****: 
******: 
**********: 
****: 
+0

THA你好样的先生 – MikeJ