# Min and max in arrays

• 5
• Locked
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 (11)
You must be signed in to leave a comment
furius72
Level 9 , Milan, Italy
15 November 2022, 12:42
Array not Arraylist.....
Xavi Martin
Level 22
Expert
26 October 2022, 06:57
I have a question, in the for loop that we use to perform the check, why do we start the loop i =1, instead of i=0;
Pavel Naumovich
Level 16 , Chippenham, United Kingdom
25 September 2020, 21:39
Arrays.sort() method makes live easier
Show How
Level 13 , Manchester, United Kingdom
1 May 2020, 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 27 , Spanish Town, Jamaica
24 April 2020, 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 A
Level 18 , Rubery, United Kingdom
2 June 2020, 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 Hervey Software Engineer/Consult at Zeal IT ConsultantsExpert
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 Hervey Software Engineer/Consult at Zeal IT ConsultantsExpert
21 November 2019, 04:14
Ugghh I did this with an ArrayList....so failed #1. Starting over
Tommy Guinness
Level 15 , Newcastle West, Ireland
15 October 2019, 20:23
Hi Guys need help. Cant meet 3rd requirements but output its ok i think.
Roman
Level 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.
Janusz
Level 11 , Radomsko, Poland
21 January 2019, 16:01
Very good training.