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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:12:35+00:00 2026-05-28T07:12:35+00:00

Basically, what I want to do is check two integers against a given value,

  • 0

Basically, what I want to do is check two integers against a given value, therefore, classically what you would do is something like this:

//just to get some values to check
int a, b;
a = (int)(Math.random()*5);
b = (int)(Math.random()*5);

//the actual thing in question
if(a == 0 || b == 0)
{
//Then do something
}

But is there a more concise format to do this? Possibly similar to this (which returns a bad operand type):

//just to get some values to check
int a, b;
a = (int)(Math.random()*5);
b = (int)(Math.random()*5);

//the actual thing in question
if((a||b) == 0)
{
//Then do something
}
  • 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-28T07:12:36+00:00Added an answer on May 28, 2026 at 7:12 am

    Unfortunately there is no such construct in Java.

    It this kind of comparison is frequent in your code, you can implement a small function that will perform the check for you:

    public boolean oneOfEquals(int a, int b, int expected) {
        return (a == expected) || (b == expected);
    }
    

    Then you could use it like this:

    if(oneOfEquals(a, b, 0)) {
        // ...
    }
    

    If you don’t want to restrict yourselft to integers, you can make the above function generic:

    public <T> boolean oneOfEquals(T a, T b, T expected) {
        return a.equals(expected) || b.equals(expected);
    }
    

    Note that in this case Java runtime will perform automatic boxing and unboxing for primitive types (like int), which is a performance loss.

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

Sidebar

Related Questions

Basically I just want to check if one time period overlaps with another. Null
Basically, I'm doing this: var phone = $(#phone).val(); Then I want to check if:
Basically I want to check what url the user is on and compare it
I basically want to do this: grep 'example.com' www_log > example.com.YYYY-MM-DD-H:i:S.log ...with of course
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I basically want to make things easier by just looping LinkButtons instead of making
I just basically want to add about 20 and sometimes 80 Proximity Alerts with
I'm looking for a method in Ruby which is basically this: io.ready_for_read? I just
Basically my dictionary looks like: object:[NSNumber numberWithBool:] key: [NSNumber numberWithInteger:ID] I want to add
I basically want to take two images taken from the camera on the iPhone

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.