programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# How can I fix this program to find the middle value in the longest vacant space in an array?

Jos Kos
Greenhorn
Posts: 1
Hello everyone! First of all Im very new and this is a very nice website. Thank you for this site.

My question might be broad but I wish to make it understandable.

I had to make a program through following these steps I'm sure you'll understand what I'm doing here through reading the steps.

This is the code. And this is what the output should have been but it's not and my code isn't working.

This PDF file: https://uploadfiles.io/mem8p
Has the solution code but it's not working either. Could you please help me fix this code and make this excercise? It's not graded it's just for training. Please I require your help.

Also this is the assignment description:

" It is a well-researched fact that men in a restroom generally prefer to maximize
their distance from already occupied stalls, by occupying the middle of the longest
sequence of unoccupied places.
For example, consider the situation where ten stalls are empty.
_ _ _ _ _ _ _ _ _ _
The first visitor will occupy a middle position:
_ _ _ _ _ X _ _ _ _
The next visitor will be in the middle of the empty area at the left.
_ _ X _ _ X _ _ _ _
Write a program that reads the number of stalls and then prints out diagrams in the
format given above when the stalls become filled, one at a time. Hint: Use an array of
boolean values to indicate whether a stall is occupied."

s ravi chandran
Ranch Hand
Posts: 579
6
I think there is a problem at this point:

1) you are not incrementing variable i in this while loop.
2) if l=i, what is supposed to happen for initial condition i=0?