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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:36:11+00:00 2026-06-10T22:36:11+00:00

I have a class obj , which has three properties: firstValue , secondValue ,

  • 0

I have a class obj, which has three properties: firstValue, secondValue, thirdValue, all of which range from 0 to 255.

I have a List containing objects of class obj and must divide them into 32 different regions according to the values of firstValue, secondValue and thirdValue. I have been successful using a nested if-else statement like this:

if (obj.firstValue < 15 )
{
    if(obj.secondValue <200)
    {
        if(obj.thirdValue <125)
            maincolor[0]++;
        else
            maincolor[1]++;
    }
    else
    {
        if (obj.thirdValue < 125)
            maincolor[2]++;
        else
            maincolor[3]++;
    }
}
else if (obj.firstValue < 41)
{
    if (obj.secondValue < 200)
    {
        if (obj.thirdValue < 125)
            maincolor[4]++;
        else
            maincolor[5]++;
    }
    else
    {
        if (obj.thirdValue < 125)
            maincolor[6]++;
        else
            maincolor[7]++;
    }
}
else if (obj.firstValue < 90)
{
    if (obj.secondValue < 200)
    {
        if (obj.thirdValue < 125)
            maincolor[8]++;
        else
            maincolor[9]++;
    }
    else
    {
        if (obj.thirdValue < 125)
            maincolor[10]++;
        else
            maincolor[11]++;
    }
}
else if (obj.firstValue < 128)
{
    if (obj.secondValue < 200)
    {
        if (obj.thirdValue < 125)
            maincolor[12]++;
        else
            maincolor[13]++;
    }
    else
    {
        if (obj.thirdValue < 125)
            maincolor[14]++;
        else
            maincolor[15]++;
    }
}
else if (obj.firstValue < 166)
{
    if (obj.secondValue < 200)
    {
        if (obj.thirdValue < 125)
            maincolor[16]++;
        else
            maincolor[17]++;
    }
    else
    {
        if (obj.thirdValue < 125)
            maincolor[18]++;
        else
            maincolor[19]++;
    }
}
else if (obj.firstValue < 196)
{
    if (obj.secondValue < 200)
    {
        if (obj.thirdValue < 125)
            maincolor[20]++;
        else
            maincolor[21]++;
    }
    else
    {
        if (obj.thirdValue < 125)
            maincolor[22]++;
        else
            maincolor[23]++;
    }
}
else if (obj.firstValue < 205)
{
    if (obj.secondValue < 200)
    {
        if (obj.thirdValue < 125)
            maincolor[24]++;
        else
            maincolor[25]++;
    }
    else
    {
        if (obj.thirdValue < 125)
            maincolor[26]++;
        else
            maincolor[27]++;
    }
}
else
{
    if (obj.secondValue < 200)
    {
        if (obj.thirdValue < 125)
            maincolor[28]++;
        else
            maincolor[29]++;
    }
    else
    {
        if (obj.thirdValue < 125)
            maincolor[30]++;
        else
            maincolor[31]++;
    }
}

I use maincolor[i] to record the maximum number of the region.

The above method works, but I would like to know if there is any way to make it more readable and less of a performance cost?

  • 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-10T22:36:13+00:00Added an answer on June 10, 2026 at 10:36 pm

    This answer is almost similar to most of the answers here. I just want to stress the use of the break once you found a matching value here:

            int[] limitList = new int[] { 15, 41, 90, 128, 166, 196, 205 };
            int index = 0;
            foreach(int val in limitList)
            {
                if (obj.firstValue < val)
                    break; //break on first encounter
                index += 4;
            }
    
            if (obj.secondValue >= 200)
                index+=2;
    
            if (obj.thirdValue >=125)
                index++;
    
            maincolor[index]++;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which has some methods like follows (And more): template<class T>
I have a custom class in Obj-C called RouteManager which contains an array of
I have a module called Plants which has a const_missing method and a class
All objects in my program inherit from a Container class. The Container class has
I have a class template which inherits from a base class template. The base
I have a class defined as: class Obj { public: int width, height; Obj(int
I have my class, where I overloaded the ! operator: class obj { public:
If I have this: class A: def callFunction(self, obj): obj.otherFunction() class B: def callFunction(self,
I have a Class with generic type: class Foo<T> { protected boolean validateType(Object obj){
I have a class public class A<T> { public static string B(T obj) {

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.