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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:16:17+00:00 2026-05-22T01:16:17+00:00

I am trying to think of an algorithm where I can create number of

  • 0

I am trying to think of an algorithm where I can create number of possible binary combinations for my inference engine implementation

in short if input file to my program has 4 distinct variables my program should be able to generate

0000
0001
0010
.
.
.
1111

combinations…. So far my approach to this problem is as below which is just a thought as it is hard coded at the moment… Basically I need algorithm to generate this for any given number of variable “n”.

My Code so far…

public class TTAlgorithm {

    public static void main(String[] args) {
        Integer j = new Integer(10);

        for (int i = 0; i < 4096; i++) {
            if (j.toBinaryString(i).length() == 1) {
                System.out.println("0000000000" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 2) {
                System.out.println("000000000" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 3) {
                System.out.println("00000000" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 4) {
                System.out.println("0000000" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 5) {
                System.out.println("000000" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 6) {
                System.out.println("00000" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 7) {
                System.out.println("0000" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 8) {
                System.out.println("000" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 9) {
                System.out.println("00" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 10) {
                System.out.println("0" + j.toBinaryString(i));
            }

            if (j.toBinaryString(i).length() == 11) {
                System.out.println("" + j.toBinaryString(i));
            }
        }

    }
}

Thanks for any help….

  • 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-22T01:16:17+00:00Added an answer on May 22, 2026 at 1:16 am

    This should work…

    public static void main(String[] args) throws Exception {
            int count = 0;
    
            int stringSize = 4;
            int maxValue= (int)Math.pow(2, stringSize);
    
            while(count < maxValue) {
                String binaryString = Integer.toBinaryString(count);
    
                while(binaryString.length() < stringSize) {
                    binaryString = "0" + binaryString;
                }
    
                System.out.println(binaryString);
                count++;
            }
    
        }
    

    Output is…

    0000
    0001
    0010
    0011
    0100
    0101
    0110
    0111
    1000
    1001
    1010
    1011
    1100
    1101
    1110
    1111
    

    Put that in a method and have the method take an argument “stringSize” or whatever you want to call it.

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

Sidebar

Related Questions

I'm trying to think of a way to create a plugin architecture for my
I'm trying to write an application that can be used to create pictures that
I was trying to think an algorithm for naming an array. For example, it
I am trying to find out if it is possible to use Dijkstra's algorithm
I'm trying to create a function to read Morse code from one file, convert
I've been trying many times to create an algorithm to extract stroke information from
I'm trying to create an algorithm that set some relevance to a webpage based
I'm trying to implement a polyline simplification algorithm. The original article can be found
I could solve this using loops, but I am trying think in vectors so
I'm trying to think of clever, clear, and simple ways to write code that

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.