Reputation: 8400
How to initialize a single element to be true rather than initializing the whole array.
do {
if (flightClass == 1) {
Arrays.fill(seats, true);
} else if (flightClass == 2) {
Arrays.fill(seats, true);
}
} while (i <= 10);
My approach was to do this....
do {
if (flightClass == 1) {
int enterSeat = input.nextInt();
Arrays.fill(seats[enterSeat], true);
} else if (flightClass == 2) {
Arrays.fill(seats, true);
}
} while (i <= 10);
}
Upvotes: 0
Views: 4232
Reputation: 13713
You can simply write
seats[enterSeat] = true
to set a single array element.
Comment: It is, however, strange to put everything into the while loop, and it is even more strange not to change i
inside the loop. Are you sure your logic is correct?
Upvotes: 3
Reputation: 235984
Instead of this:
Arrays.fill(seats[enterSeat], true);
Simply do this:
seats[enterSeat] = true;
Upvotes: 5