Java 特殊回路

Java 特殊回路,java,for-loop,iteration,Java,For Loop,Iteration,嘿,我想做一个循环,接受这个数组: String[] arr = new String[3]; arr[0] = "one "; arr[1] = "two "; arr[2] = "three "; 和产出: one two three one one two two three three one one one two two two three three three 本质上,我希望它在每次迭代中增加显示每个数组值的次数。对于(int I=1;I该代码将导致异常:您正在声明一个包含2

嘿,我想做一个循环,接受这个数组:

String[] arr = new String[3];
arr[0] = "one ";
arr[1] = "two ";
arr[2] = "three ";
和产出:

one two three one one two two three three one one one two two two three three three

本质上,我希望它在每次迭代中增加显示每个数组值的次数。

对于(int I=1;I该代码将导致异常:您正在声明一个包含2个位置的数组并为其分配3个值。arr[2]将导致异常(超出范围)

for (int i=1; i<=n; i++) {
    for (int j=0; j<3; j++) {
        for (int k=0; k<i; k++) {
            System.out.print(arr[j] + " ");
        }
    }
}
使用嵌套循环打印内容。

for(int i=0;i还有另一种方法:

  for(int i=0;i<Array.length;i++)
        {
            for(int j= 0 ;j<Array.length;j++)
                {
                    for(int k=0;k<=i;k++)
                        {
                        System.out.println(""+Array[j]);
                         }
                }
        }
String[] array = {"One ","Two ", "Three "};
int n = 10;
int counter = 1;

        for(int i =0;i<n;i++){
            for(int j=0;j<array.length;j++){
                String element = array[j];
                for(int k=0;k<counter;k++){
                    System.out.print(element+" ");
                }
            }
            counter++;
            System.out.println();
        }
String[]数组={“一”、“二”、“三”};
int n=10;
int计数器=1;

对于(int i=0;这听起来像是一个家庭作业问题……试着玩Math.floor,我想你的意思是“新字符串[3];”你是如何实现它的?我的意思是你一定已经尝试过了。对吗?想想如果你把一个for循环放到另一个for循环中会发生什么。@Adeel Ansari我很糟糕,我后来进入了线程^^^遗憾的是有人已经给出了答案,而不是Ian没有考虑如何得到答案,并且会在下一个循环中陷入困境他必须编写OP pro的代码vided,初始化数组的代码。