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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:50:00+00:00 2026-06-02T11:50:00+00:00

I found a question online: Given input size print all well formed numbers of

  • 0

I found a question online: Given input size print all well formed numbers of that size.

Example: size = 3
Numbers: 123, 234, 125 etc. Condition, say number is abc then a < b < c

I am trying to write a recursive code for this and since I suck at recursion am not able to figure out the base case, or how to come out of the recursion. I had one idea:

  1. I start from with lowest well formed number of the given size (just fill array with for loop). Say size = 3, I start with 123. Then I go on till arr[0] == (10 - size)) cause that is the max value of arr[0] for the given size to be a well formed number.

My function would be printNumbers(int arr[], int size)

But am not sure if this would work. Need some pointers on the right direction.

public void findNumbers(int arr[], int size, int pos)
    {
        if(arr[0] == (10 - size))
            return;
        if(arr[pos] == (10 - size + pos))
        {
            pos--;
            findNumbers(arr,size,pos);
        }
        System.out.println(Arrays.toString(arr));
        arr[pos] = arr[pos] + 1;
        findNumbers(arr,size,pos);
    }

    public static void main(String[] args)
    {
        int size = 3;
        int pos = size-1;
        int arr[] = new int[size];
        for(int i = 0; i<size; i++)
        {
            arr[i] = i+1;
        }
        //System.out.println(Arrays.toString(arr));
        WellFormed obj = new WellFormed();
        obj.findNumbers(arr, size, pos);
    }
  • 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-02T11:50:02+00:00Added an answer on June 2, 2026 at 11:50 am
    import java.util.Arrays;
    
    public class WellFormed {
    
        public static int maxDigit;
    
        public void findNumbers(int[] digits, int start, int currPos) {
            if (currPos >= digits.length) {
                System.out.println(Arrays.toString(digits));
                return;
            }
    
            int maxDigitInCurrPos = maxDigit - digits.length + currPos + 1;
            for (int i = start; i <= maxDigitInCurrPos; i++) {
                digits[currPos] = i;
                findNumbers(digits, i+1, currPos + 1);
            }
        }
    
        public static void main(String[] args)
        {   
            WellFormed obj = new WellFormed();
            maxDigit = 5;
            int inputSize = 3;
            int[] digits = new int[inputSize];
            obj.findNumbers(digits, 1, 0);
        }
    }
    

    This works fine:

    For inputSize = 3 and maxDigit = 5, output is:
    
    [1, 2, 3]
    [1, 2, 4]
    [1, 2, 5]
    [1, 3, 4]
    [1, 3, 5]
    [1, 4, 5]
    [2, 3, 4]
    [2, 3, 5]
    [2, 4, 5]
    [3, 4, 5]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reinstating this question with a bounty! I need an example that stays online ,
I found this open question online. How do you process a large data file
Found this question that explained a way to communicate between layers. However there is
I found this question that is discussing what I would like to do, but
I found this question that was very useful in learning the basics of the
I found this question on an online forum: Really interested on how it can
I found a Flash program online that would be perfect for a project I'm
Question: Given a sorted array A find all possible difference of elements from A.
Some time ago I found a reference online to a database system that stored
I found a Question similar to my problem( Regular Expression For URL Query )

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.