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

  • Home
  • SEARCH
  • 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 7878017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:32:27+00:00 2026-06-03T03:32:27+00:00

I need to use recursion to for a method I’m trying to implement. The

  • 0

I need to use recursion to for a method I’m trying to implement. The problem is recursion here isn’t working as I thought it would. Here’s the code I have and I’ll explain further below.

    public void printer(int level) { 
    System.out.println("A Car " + getId());
    for (int j=0; j< carTypes.size(); j++) {

        carTypes.get(j).printer( Index.get(j)+1);
        if (carTypes.get(j) instanceof Toyota) {
            level = 1;
        }
        else {
            level = 1;
            for (int i = 0; i <= j; i++){
                if (j == Index.size()-1) 
                    break;
                if (Index.get(i) == Index.get(j+1)) {
                    number++;
                }
            }
        }
        System.out.println("Is recursion working right?");

    }//End of for loop
}

The problem I am having is I was hoping that everything after carTypes.get(j).printer( Index.get(j)+1); would be ignored and the method would be looped. I know if this happens, I will have to find another to deal with my for loop but for now, I just want the recursion working. I am not entirely sure if the information I have provided is enough so if you need more just ask I’ll happily give more info.

Thanks

  • 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-03T03:32:28+00:00Added an answer on June 3, 2026 at 3:32 am

    Recursion: Calling a method from itself.

    Now, carTypes.get(j).printer( Index.get(j)+1); this line calls printer method each time but on different object.

    So, in fact you are not calling same printer method, and hence recursion is not happening.

    EDIT :

    I know if this happens, I will have to find another to deal with my for loop but for now, I just want the recursion working.

    Replace

    carTypes.get(j).printer( Index.get(j)+1);
    

    with

    printer( Index.get(j)+1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use a forward chainer in certain Prolog problem. I would like
I have 2 solutions to a recursion problem that I need for a function
Need to use own imaged markers instead built-in pins. I have several questions. 1.
I need to use cv::FindContours() in a program and I have to know the
I need to segment text using fullstops using PHP/Javascript.The problem is if I use
I'm kinda new to programming and need help doing a recursive method.I have a
I have a problem, I need to retrieve a single field from a single
Here is my code. Recursion: #include <stdio.h> int Recursion(int m,int n) { if(m==0 ||
I need to write a non-recursive version of the function sum-squares and Use a
So, I need use this event so I can navigate trought blog posts. 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.