Search code examples
javanested-loopsbluej

nested loops pattern java


I have been struggling with this pattern,trying to use only the code required for a nested FOR loop. I am required not to use patterns,just a nested for loop:

123454321
1234 4321
123   321
12     21
1       1

The code required is Java and I am using BlueJ compiler.


Solution

  • Here you go. A nested for loop, which gives the desired output.

    String s[] = new String[]{"123454321","1234 4321","123   321","12     21","1       1"};
    for(int i=0; i<=0;i++)// for the nested loop
      for(String x:s)
        System.out.println(x);