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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:06:51+00:00 2026-06-11T09:06:51+00:00

Here is the subject: I have a LinkedList list , if the list has

  • 0

Here is the subject:

I have a LinkedList list, if the list has 3 elements, I’d like to list an entire truth table for it, for instance:

a b c   <---   the three elements in list
0 0 0
0 0 1
0 1 0
1 0 0
1 1 1
1 1 0
1 0 1
0 1 1

and if the list has 4 or more elements, I would like to generate a more large table.

But I got stuck here:

I know writing loops like this can generate the entire table:

       for (int a = 0; a < 2; a++){
            for (int b = 0; b < 2; b++) {
                for (int c = 0; c < 2; c++) {
                    for (int d = 0; d < 2; d++) {
                        System.out.println(a + " " + b + " " + c + " " + d);
                    }
                }
            }
        }

but I can’t change the number of loops based on the list size, and I think writing special cases for this is unacceptable, so is there an alternative way to do this??

  • 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-11T09:06:52+00:00Added an answer on June 11, 2026 at 9:06 am

    simple solution if you just want a truth table:

    code:

    int len = 3;
    int num = (int)Math.pow(2, len);
    for(int i=0; i<num; i++){
        // http://stackoverflow.com/a/4421438/1273830
        System.out.println(String.format("%"+len+"s", Integer.toBinaryString(i)).replace(' ', '0'));
    }
    

    Basic digital logic: truth tables are binary number sequences.

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

Sidebar

Related Questions

once more i'm here asking help on seam subject. Currently we have the following
i have the following code $subject = Subject Here; $headers = 'MIME-Version: 1.0' .
Like the subject says I have a listview, and I wanted to add the
Not sure if I have the correct subject line. Here is my issue. I
Here is the dev guide related to the subject http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems So we have in
I've seen a lot of discussion about this subject on here. If i have
I have this json string {Table : [{subject : No Records are there to
I am using hibernate 3 , oracle 10g. I have a table: subject. The
Like many people already seem to have (there are several threads on this subject
i have a problem as subject said. i have a Table courses in sql

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.