Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:41:24+00:00 2026-06-05T01:41:24+00:00

currently recursion is fresh & difficult topic for me, however I need to use

  • 0

currently recursion is fresh & difficult topic for me, however I need to use it in one of my algorithms.

Here is the challenge:

I need a method where I specify number of recursions (number of nested FOR loops) and number of iterations for each FOR loop. The result should show me, something simmilar to counter, however each column of counter is limited to specific number.

ArrayList<Integer> specs= new ArrayList<Integer>();
  specs.add(5); //for(int i=0 to 5; i++)
  specs.add(7);
  specs.add(9);
  specs.add(2);
  specs.add(8);
  specs.add(9); 

public void recursion(ArrayList<Integer> specs){
  //number of nested loops will be equal to: specs.size();
  //each item in specs, specifies the For loop max count e.g:
  //First outside loop will be: for(int i=0; i< specs.get(0); i++)
  //Second loop inside will be: for(int i=0; i< specs.get(1); i++)
  //...
}

The the results will be similar to outputs of this manual, nested loop:

    int[] i;
    i = new int[7];

    for( i[6]=0; i[6]<5; i[6]++){
        for( i[5]=0; i[5]<7; i[5]++){
            for(i[4] =0; i[4]<9; i[4]++){
                for(i[3] =0; i[3]<2; i[3]++){
                    for(i[2] =0; i[2]<8; i[2]++){
                        for(i[1] =0; i[1]<9; i[1]++){
                            //...
                            System.out.println(i[1]+" "+i[2]+" "+i[3]+" "+i[4]+" "+i[5]+" "+i[6]);
                        }
                    }
                }
            }
        }
    }

I already, killed 3 days on this, and still no results, was searching it in internet, however the examples are too different. Therefore, posting the programming question in internet first time in my life. Thank you in advance, you are free to change the code efficiency, I just need the same results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:41:25+00:00Added an answer on June 5, 2026 at 1:41 am

    Does this snippet give the output you want? (It is compileable and executeable)

    import java.util.ArrayList;
    import java.util.List;
    
    public class SO {
    
        static ArrayList<Integer> specs = new ArrayList<Integer>();
        static int[] i;
    
        public static void main(String[] args) throws Exception {
            specs.add(5); //for(int i=0 to 5; i++)
            specs.add(7);
            specs.add(9);
            specs.add(2);
            specs.add(8);
            specs.add(9);
            i = new int[specs.size()];
            printMe(0, specs, i);
        }
    
        static void printMe(int depth, List<Integer> _specs, int[] i) {
            if (_specs.isEmpty()) {
                System.out.println(printI(i));
                return;
            } else {
                for (int j = 0; j < _specs.get(0); j++) {
                    i[depth] = j + 1; // + 1 since you seems to want to go from 1 and not 0
                    printMe(depth + 1, _specs.subList(1, _specs.size()), i);
                }
            }
        }
    
        static String printI(int[] i) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < i.length; j++) {
                sb.append(i[j]);
                if (j < i.length - 1) {
                    sb.append(" ");
                }
    
            }
            return sb.toString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently studying recursion in school, and I have trouble thinking about methods
Currently we use jQuery to add RIA goodness to our apps, but recently we
Currently i am having problems with a makefile due to some unexpected recursion and
I am currently working on a function in which I use a recursive CTE,
I'm currently just working my way through some recursion problems, and I am currently
So I'm currently trying to grasp the concept of recursion, and I understand most
I'm trying to modify my web page, which I currently use QueryStrings to display
I'm writing a text tag parser and I'm currently using this recursive method to
I currently use the following command, but it's a little unwieldy to type. What's
Currently Im getting familiar with recursion and in trying to achieve further understanding i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.