Min and max in arrays

  • 5
The Fault Line residential zone has only 20 houses, but their numbers were assigned haphazardly. It turns out that Fault Line's starting and ending numbers were set randomly. That's what makes it so interesting and unpredictable! Let's write a little Fault Line emulator: we'll determine where its begins and where it ends. To do this, we'll cram the housing block into an array, populate it with house numbers, and find the largest and the smallest among them.
You can't complete this task, because you're not signed in.
Comments(8)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Show HowLevel 12 , Manchester
1 May, 22:56
I always initialize min and max variables in such situation like this: int min = Integer.MAX_VALUE and int max = Integer.MIN_VALUE. This way my variables are initialized to the highest and lowest an integer can hold. It can makes life easier in my opinion.
Adrian Level 14 , Spanish Town
24 April, 23:07
very sneaky! if you initialize the maximum and minimum variables before populating the array, they will store a default "0". your maximum variable will appear to work (for values that aren't negative) but your minimum will fail for values greater than "0". seems pretty obvious but I'm sure others will be caught by it too.
Devonte ALevel 8 , Rubery
Tuesday, 13:38
Yes! initialize the maximum and minimum variables before populating the array and it failed the third test case. So i would recommend doing the max and min separately to populating the Array.
Kent HerveyLevel 13
21 November 2019, 04:26
Ugh It is my practice to make the number of elements in the collection to be declared as a constant so I can build it with 3, then change to the required number at the end. It has always worked, but not this time. I had to hard code the number...in this case 20.
Kent HerveyLevel 13
21 November 2019, 04:14
Ugghh I did this with an ArrayList....so failed #1. Starting over
Tommy GuinnessLevel 15 , Newcastle West
15 October 2019, 20:23
Hi Guys need help. Cant meet 3rd requirements but output its ok i think.
RomanLevel 41
16 October 2019, 05:58
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
JanuszLevel 11 , Radomsko
21 January 2019, 16:01
Very good training.