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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:10:30+00:00 2026-06-04T04:10:30+00:00

Hey guys I was wondering if there was any way to return a certain

  • 0

Hey guys I was wondering if there was any way to return a certain fraction of a bunch of booleans in java. Simply put I would like to find out if there is a way to create a method that when given four booleans if three of them are true it returns true but if less than three are true it returns false.
I know this might be hard to understand and if you don’t understand just post a comment saying so.

  • 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-04T04:10:32+00:00Added an answer on June 4, 2026 at 4:10 am

    Weird question … anyway, here’s a possible solution for just 4 booleans:

    public boolean booleanFraction(boolean a, boolean b, boolean c, boolean d) {
        int ia = a ? 1 : 0;
        int ib = b ? 1 : 0;
        int ic = c ? 1 : 0;
        int id = d ? 1 : 0;
        return ia + ib + ic + id == 3;
    }
    

    For a more general solution, here’s a method that receives as parameters the number of booleans that need to be true for considering true the whole expression, and a greater than zero variable number of boolean values:

    public static boolean booleanFraction(int number, boolean... bools) {
        int acc = 0;
        for (boolean b : bools)
            acc += b ? 1 : 0;
        return acc == number;
    }
    

    Call it like this, for the example in the question:

    booleanFraction(3, true, true, true, false);
    > true
    
    booleanFraction(3, false, false, true, false);
    > false
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I was wondering if there is a way to get a certain
Hey guys i was wondering if there was a way to detect if the
Hey guys I was wondering if there was a way to change he upper
Hey guys, i was wondering if you would help me a little with my
Hey guys I was wondering how I would get the highest id in wordpress.
Hey guys, just wondering if their is a simple way to create an Item
Hey guys I was wondering if there is a script that allows me to
Hey guys! Was wondering is anyone had any suggestions on books or other resources
Hey guys, I was wondering if you would be able to help me use
Hey guys, I am using Apache Ant and I am wondering how would I

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.