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 7553203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:59:02+00:00 2026-05-30T10:59:02+00:00

I am trying to learn programming and I am on the phase of learning

  • 0

I am trying to learn programming and I am on the phase of learning recursion. Before this, I have successfully solve the problem but using loops. Right now, since recursion is quite interesting to me, I was wondering if I could convert the loop into a recursive method. I have done my attempts but I’ve been getting a sort of infinite computation whatsoever.

Can somebody give me a hand with this? Thanks.

This is my code.

public class RecursiveProduct {


public static void main (String[] args) {

    Scanner myInput = new Scanner(System.in);

    System.out.print("Enter num1: ");
    int num1 = myInput.nextInt();

    System.out.print("Enter num2: ");
    int num2 = myInput.nextInt();

    int product = recursiveProduct(num1, num2);

    System.out.print(num1 +" * " +num2 +" = " +product);


}

public static int recursiveProduct(int a, int b)
{
    int result = 0;

    if(b == 0)
        return result;
    else
    {
        result += a;
        return result += recursiveProduct(a, b--);
    }
}


}
  • 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-05-30T10:59:03+00:00Added an answer on May 30, 2026 at 10:59 am

    Try this:

    public static int recursiveProduct(int a, int b) {
      if (b == 0) {
        return 0;
      } else {
        return a + recursiveProduct(a,--b);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn Objective-C and iPhone programming, but I'm stuck with a problem.
I'm trying to learn iOS (4.3) programming and got stuck on this. I'm using
This is quite n00bish, but I'm trying to learn/understand functional programming in python. The
I have been trying to learn multi-threaded programming in C# and I am confused
Original Question: This is my first post ever. I'm trying to learn ios programming
I'm trying to learn 3d graphics programming through Learning Modern 3D Graphics Programming by
Disclaimer: I'm trying to learn proper OO programming/design, so I'm pretty new to this
I am trying to learn inline assembly programming in Delphi, and to this end
I am trying to learn perl programming and am using it to read a
I'm trying to learn some graphics programming using C. What would be the best

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.