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
A retailer is able to track which products draw the most attention from its customers through the use of 5g-enabled motion senso
Minchanka [31]

The technology combines with 5g capabilities to allow the monitoring of shopping trends in this way is called internet of things

For better understanding, lets explain what internet of things means.

  • Internet of things is simply known to be a network of Internet-Enabled objects that is often combined along with web services as they often interact with these objects.
  • There is a known development of the Internet where objects always have network connectivity giving them room to send and receive data.

From the above, we can therefore say that the answer The technology combines with 5g capabilities to allow the monitoring of shopping trends in this way is called internet of things is correct.

Learn more about internet of things from:

brainly.com/question/19995128

7 0
3 years ago
Binary is used to store what on a computer?<br> •Data<br> •Dates<br> •Address
solmaris [256]

Answer:

Data................

5 0
3 years ago
Read 2 more answers
It is a good idea to include your teacher’s name on a title page.
kkurt [141]
I usually include my teachers name in the upper right hand corner along with the date my name and the subject.
6 0
4 years ago
Read 2 more answers
Write a program in C/C++ to draw the following points: (0.0,0.0), (20.0,0.0), (20.0,20.0), (0.0,20.0) and (10.0,25.0). For this
Fed [463]

Introductory program; just a static picture of a colored triangle.
Shows how to use GLUT.
Has minimal structure: only main() and a display callback.
Uses only the default viewing parameters (in fact, it never mentions viewing at all). This is an orthographic view volume with bounds of -1..1 in all three dimensions.
Draws only using glColor and glVertex within glBegin and glEnd in the display callback.
Uses only the GL_POLYGON drawing mode.
Illustrates glClear and glFlush.
triangle.cpp
// A simple introductory program; its main window contains a static picture
// of a triangle, whose three vertices are red, green and blue. The program
// illustrates viewing with default viewing parameters only.

#ifdef __APPLE_CC__
#include
#else
#include
#endif

// Clears the current window and draws a triangle.
void display() {

// Set every pixel in the frame buffer to the current clear color.
glClear(GL_COLOR_BUFFER_BIT);

// Drawing is done by specifying a sequence of vertices. The way these
// vertices are connected (or not connected) depends on the argument to
// glBegin. GL_POLYGON constructs a filled polygon.
glBegin(GL_POLYGON);
glColor3f(1, 0, 0); glVertex3f(-0.6, -0.75, 0.5);
glColor3f(0, 1, 0); glVertex3f(0.6, -0.75, 0);
glColor3f(0, 0, 1); glVertex3f(0, 0.75, 0);
glEnd();

// Flush drawing command buffer to make drawing happen as soon as possible.
glFlush();
}

// Initializes GLUT, the display mode, and main window; registers callbacks;
// enters the main event loop.
int main(int argc, char** argv) {

// Use a single buffered window in RGB mode (as opposed to a double-buffered
// window or color-index mode).
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

// Position window at (80,80)-(480,380) and give it a title.
glutInitWindowPosition(80, 80);
glutInitWindowSize(400, 300);
glutCreateWindow("A Simple Triangle");

// Tell GLUT that whenever the main window needs to be repainted that it
// should call the function display().
glutDisplayFunc(display);

// Tell GLUT to start reading and processing events. This function
// never returns; the program only exits when the user closes the main
// window or kills the process.
glutMainLoop();
}
6 0
3 years ago
99 Point question
icang [17]
Smartart is your answer! Hope this helps
3 0
4 years ago
Read 2 more answers
Other questions:
  • Look at the following array definition:
    11·1 answer
  • When considering server consolidation, plan on running ___________ vCPUs per core.a. 1 to 2b. 3 to 4c. 4 to 6d. 6 to 8
    7·1 answer
  • The path to the distribution share should always be referred to by the ____ path to ensure that it can be accessed over the netw
    6·1 answer
  • Which service enables administrators to execute a command on remote computers using windows powershell or the windows remote she
    6·1 answer
  • What is computer <br> What is scratch
    10·2 answers
  • how does modern information technology has affected society ?? Need help on how it has affected society
    10·1 answer
  • How can I put my keyboard back​
    9·1 answer
  • When do you use an else statement for coding
    6·1 answer
  • 12. How many different documents can<br> you have open at one time?
    8·1 answer
  • PORFA AYUDAAAA DOY CORONA (solo si puedo) ES DE TECNOLOGÍA
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!