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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:45:28+00:00 2026-06-13T07:45:28+00:00

I have the following two methods: public int Average (params int[] array) { if

  • 0

I have the following two methods:

public int Average (params int[] array)
{
    if (array.Length > 0)
    { 
        double avg = Sum(ints) / arr.Length;        
        return (int)avg;             
    }        
    return 0;
} 

public int Sum(params int[] array2)
{
    int total = 0;
    for (int n = 0; n < array2.Length; n++)
    {
        total += arr[n];
    }
    return total;
}

But for testing purposes I tried adding the int.MaxValue / 2 and int.MaxValue / 2 + 4. in the array. But why does the unit test fail, although the sum of the two values will be less than int.MaxValue?

  • 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-13T07:45:29+00:00Added an answer on June 13, 2026 at 7:45 am

    two values in the array[] :- int.MaxValue / 2 & int.MaxValue / 2 + 4.. but when i run the unit test it fails,, although the sum of the two values will be less than int.maxvalues?

    No sir, the sum will be more than int.MaxValue:

    (int.MaxValue / 2) + (int.MaxValue / 2 + 4) == int.MaxValue + 4 //...
    

    You overflew the int max value.

    Simple math: (x/2)+ (x/2 +4) == x+4

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

Sidebar

Related Questions

I have two methods: public ActionResult Index(int? id) { return Redirect(/View/ + this.GetMenuItems().First().Id); }
I have the following C# methods: public Vector2 GetVectorToTile(int x, int y) { return
I have the following two methods Method 1 public String[] getSongIds(String whereClause) { String
I have the following two methods that (as you can see) are similar in
I have the following two methods for getting data from my database: - (void)
I have the following two tables Groups Id (int) People Id (int) GroupId (int,
I have the following two queries. SELECT account_name,SUM(amount) AS AMOUNT1 FROM entries LEFT JOIN
I have two methods in my Web API controller as follows: public samplecontroller: webapicontroller
Say I have the following: class Base { public Base (int n) { }
Two of the class properties have the following annotations: [Key] [Column] [Required] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public

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.