1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
g100num [7]
4 years ago
9

Write a program that reads the number of stalls and then prints out diagrams in the format given above when the stalls become fi

lled, one at a time. Hint: Use an array of boolean values to indicate whether a stall is occupied.
Computers and Technology
1 answer:
Solnce55 [7]4 years ago
3 0

Answer:

/* package whatever; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

public class Ideone

{

  public static final int STALL_COUNT = 10;

 

public static int find_stall(boolean[] stalls) {

int longest_count = -1;

int longest_length = 0;

int current_count = -1;

int current_length = 0;

boolean inRun = false;

for (int i = 0; i < stalls.length; i++) {

if (inRun && stalls[i]) {

inRun = false;

if (current_length >= longest_length) {

longest_length = current_length;

longest_count = current_count;

}

 

}

else if (!inRun && !stalls[i]) {

inRun = true;

current_count = i;

current_length = 1;

}

else if (inRun && !stalls[i]) {

current_length += 1;

}

}

if (inRun) {

if (current_length >= longest_length) {

longest_length = current_length;

longest_count = current_count;

}

}

return (longest_length - 1) / 2 + longest_count;

}

 

public static void print_pattern(boolean[] stalls) {

for (int i = 0; i < stalls.length; i++) {

if (stalls[i]) {

System.out.print("X ");

}

else {

System.out.print("_ ");

}

}

System.out.println();

}

 

  public static void main (String[] args) throws java.lang.Exception

  {

      boolean[] stalls = new boolean[STALL_COUNT];

for (int i = 0; i < stalls.length; i++) {

stalls[find_stall(stalls)] = true;

print_pattern(stalls);

  }

}

}

You might be interested in
Why are medical coders using encoded software
EastWind [94]
To keep the medical records confidential otherwise, hackers would take advantage of them and sell them to the highest bidder 
3 0
3 years ago
It's best to use assertive speech when you<br> I want to show respect. *<br> True<br> False
mestny [16]

Answer:

True

Explanation:

Hope this helps :)

6 0
3 years ago
Read 2 more answers
When the location of a data source is defined as a(n) _______ location, excel will access the connection to the data source with
valina [46]

trusted is your answer

5 0
4 years ago
Which of the following software is cloud-based? OpenOffice Writer Word 2013 Word Online Word Perfect\
evablogger [386]
I think its open office
3 0
3 years ago
Read 2 more answers
What are the 3 biggest advancements in computers?
Georgia [21]

Answer:

abacus . Mesopotamia or China, possibly several thousand years BCE. ...

binary math . Pingala, India, 3rd century BCE. ...

punched card . Basile Bouchon, France, 1725. ...

Explanation:

:)

6 0
3 years ago
Other questions:
  • What is the legal right granted to all authors and artists that gives them sole ownership and use of their words, software, pict
    9·2 answers
  • By placing the chorale melody in the highest voice and using a simple harmonization, bach made it easier for congregation member
    5·1 answer
  • Compose a program to examine the string "Hello, world!\n", and calculate the total decimal numeric value of all the characters i
    7·1 answer
  • What can be designed to create annoying glitches or destroy data
    11·1 answer
  • Linda has written a program that works well on various operating systems, but she needs to increase the readability of the progr
    14·1 answer
  • A wide variety of "apps" are available to customize devices. Which category of app does word processing software fall into? Ente
    6·1 answer
  • A group of users is unable to connect to the network. When testing several of the PCs and issuing the command ipconfig, the tech
    10·1 answer
  • Why do Selection Sort and Insertion Sort’s outer loops run 11 iterations if there are 12 elements in the array?
    7·1 answer
  • Computer is a major source of informarion why​
    8·1 answer
  • Consider a pipelined processor with just one level of cache. assume that in the absence of memory delays, the baseline cpi of th
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!