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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:06:53+00:00 2026-06-10T23:06:53+00:00

I have a problem I’m trying to solve in Java and I cannot figure

  • 0

I have a problem I’m trying to solve in Java and I cannot figure out the algorithm that I’m going to need to follow. This problem is similar to the Bit String problem (how many bit strings are there of length x), but with some added difficulty. I’m not even sure the algorithm for solving the normal bit string problem anyway.

So here’s my actual problem:
I have 5 variables. Say Q W X Y Z. Each variable can take one of 3 values (so like bit string can take 1 or 0, but this can take say 0, 1, or 2). I need to generate all possible combinations of this “bit string”.

So one combination may be 00000 another may be 10002, another could be 22222, etc. I need to print out all combinations of this “bit string”

I’m really stumped on how to solve this problem or even come up with a decent algorithm.

Thanks for the help! Much appreciated.

  • 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-10T23:06:55+00:00Added an answer on June 10, 2026 at 11:06 pm

    To achieve this, you could just count up to your maximum value (22222 in your example) using a radix of 3. The BigInteger class supports output and instantiation with an arbitrary radix. The BigInteger class, however, does not support zerofill which is why I added this myself. Here is the resulting solution:

    public static void main( String[] args ) {
        System.out.println( new BitStrings().generateBitStrings( new BigInteger( "2222", 3 ) ) );
    }
    
    public List<String> generateBitStrings( BigInteger maxValue ) {
        final String format = "%0" + maxValue.toString( 3 ).length() + "d";
        BigInteger current = BigInteger.ZERO;
        final List<String> result = new ArrayList<String>( maxValue.intValue() );
        do {
            result.add( String.format( format, Long.valueOf( current.toString( 3 ) ) ) );
            current = current.add( BigInteger.ONE );
        } while(current.compareTo( maxValue ) <= 0);
        return result;
    }
    

    Output:

    [0000, 0001, 0002, 0010, 0011, 0012, 0020, 0021, 0022, 0100, 0101, 0102, 0110, 0111, 0112, 0120, 0121, 0122, 0200, 0201, 0202, 0210, 0211, 0212, 0220, 0221, 0222, 1000, 1001, 1002, 1010, 1011, 1012, 1020, 1021, 1022, 1100, 1101, 1102, 1110, 1111, 1112, 1120, 1121, 1122, 1200, 1201, 1202, 1210, 1211, 1212, 1220, 1221, 1222, 2000, 2001, 2002, 2010, 2011, 2012, 2020, 2021, 2022, 2100, 2101, 2102, 2110, 2111, 2112, 2120, 2121, 2122, 2200, 2201, 2202, 2210, 2211, 2212, 2220, 2221, 2222]
    

    Hope this answers your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with filling a Map in Java, I think this is simple,
I have problem with configuring NODE.JS. I was trying to install node.js with this
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with Razor syntax and jQuery, I'm trying to append some items
Have problem while getting data from Memcached on .NET MVC solution. I have this
I have problem with php's preg_match.I want to make something like this : When
I have problem in my PHP code. I'm trying to make internet shop and
I have problem like this https://dev.twitter.com/discussions/4563 if (webResponse.Headers[Content-Encoding] == gzip) { byte[] bytes =
Have problem with this code var MAIN_LOCATION = http://www.bosscaffe.com/new/; $(#gallery_page).click(function() { $('#gallery_photos').show(); getPhotos(); return
I have problem with my Java program. How I read xml -file which has

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.