answer.
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
Readme [11.4K]
2 years ago
9

Write a program that reads an integer and displays, using asterisks a filled and hollow square, placed next to each other. for e

xample if side length is 5 the program should display like so.
This program prints a filled and hollow square.
Enter the length of a side: 5
***** *****
***** * *
***** * *
***** * *
***** *****

Computers and Technology
1 answer:
Keith_Richards [23]2 years ago
4 0

Answer:

Here is the JAVA program.

import java.util.Scanner; //Scanner class to take input from user

 public class HollowFilledSquare {

          public static void main(String[] args) { //start of main() function body

    Scanner sc= new Scanner(System.in); // Scanner class object

          System.out.print("Enter an integer to display a filled and hollow square "); //prompts user to enter an integer

           int n = sc.nextInt(); // reads integer input from the user

          StringBuilder filled = new StringBuilder(n);

// creates objects filled and hollow of class StringBuilder

          StringBuilder hollow = new StringBuilder(n);

          for (int i = 1; i <= n; i++) { // outer loop for length of the square

              for (int j = 1; j <= n; j++) { // inner loop for width of square

                  filled.append("*"); //displays asterisks

                    if (i == 1 || i == n || j == 1 || j == n) // condition to display stars

                       {hollow.append("*");}

                   else

                     {  hollow.append(" ");  }             } // to display empty spaces

           System.out.println(filled + "   " + hollow);

// places hollow and filled squares next to each other

           filled. delete(0, filled.length());  

//removes characters from 0 to the length of filled square

           hollow. delete(0, hollow.length());      

//removes characters from 0 to the length of hollow square } }  }

Explanation:

The program first prompts the user to enter an integer. It uses outer loop for length of the square and inner loop for width of square in order to display the asterisks. append () function is used to display the sequence of asterisks. delete () function removes the  asterisks from the sequence of asterisks. String Builder is a class used for to create a string of n characters. It basically works like String but this is used to create modifiable objects.

The screen shot of the code along with the output is attached.

You might be interested in
How does Accenture help companies harness the power of data to achieve optimal business outcomes?
balandron [24]

Answer:

Accenture Analytics helps organizations realize measurable business value from their data by leveraging a dynamic alliance and vendor ecosystem of leading and emerging technology providers with a technology-agnostic approach to solutions development and delivery.    Hope it help's! :D

4 0
2 years ago
Read 2 more answers
This program finds the sum and average of three numbers. What are the proper codes for Lines a and b?
Gennadij [26K]

Answer:

The Proper codes in Line a and Line b is given below

average=Sum/3  

print (" Average is = ", average)

Explanation:

In the given question it calculated the sum but the program does not calculate the average of the 3 numbers.The average of the 3 number is calculated by using average=Sum/3   statement so we add this code in Line a then After that print the value of average by using the print function so we add this code in Line b.

4 0
2 years ago
Read 2 more answers
2. Because technology is always changing, there are new applications being developed constantly. (1 point)
Zepler [3.9K]
True because we need new tech
4 0
2 years ago
Read 2 more answers
In this image, which feature did we most likely use to quickly change the background, fonts, and layout?
MAVERICK [17]

Answer: themes

Explanation:

Took the test

3 0
2 years ago
Targeting encourages drivers to scan far ahead and _____________. A. focus their visual attention on the next point on the road
Colt1911 [192]
<span>A. focus their visual attention on the next point on the road.  A driver must have a target, it can be the car in front, a building pr a structure on the road.  Targeting enables the driver to look further ahead on the road and thus be ready for any obstacle on the road.</span>
3 0
2 years ago
Read 2 more answers
Other questions:
  • What is the argument in this function =AVERAGE(F3:F26)
    15·1 answer
  • Adrian has decided to create a website to catalog all the books he has in his personal library. He wants to store this informati
    11·2 answers
  • Define a function pyramid_volume with parameters base_length, base_width, and pyramid_height, that returns the volume of a pyram
    12·1 answer
  • Which of the following dimensions of e-commerce technology involves the integration of video, audio, and text marketing messages
    11·1 answer
  • Which of the following is a collection of unprocessed items, which can include text, numbers, images, audio, and video?A. DataB.
    14·1 answer
  • Which of the following statements is true? Using existing exceptions makes the program less robust. Always create your own excep
    15·1 answer
  • The Company management has asked that you compare the OSSTMM and the PTES to determine which methodology to select for internal
    13·1 answer
  • A program is divided into 3 blocks that are being compiled on 3 parallel computers. Each block takes an Exponential amount of ti
    6·1 answer
  • Why do agriculture and natural resource systems vary from state to state?
    8·1 answer
  • The microprogram counter (MPC) contains the address of the next microcode statement for the Mic1 emulator to execute. The MPC va
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!