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
Write a program for determining if a year is a leap year. In the Gregorian calendar system you can check if it is a leaper if it
SOVA2 [1]

Answer:

def leap_year_check(year):

return if int(year) % 4 == 0 and (int(year) % 100 != 0 or int(year) % 400 == 0)

Explanation:

The function is named leap_year_check and takes in an argument which is the year which we wish to determine if it's a new year or not.

int ensures the argument is read as an integer and not a float.

The % obtains the value of the remainder after a division exercise. A remainder of 0 means number is divisible by the quotient and a remainder other wise means it is not divisible by the quotient.

If the conditions is met, that is, (the first condition is true and either the second or Third condition is true)

the function leap_year_check returns a boolean ; true and false if otherwise.

8 0
1 year ago
After experiencing several issues with an Active Directory domain controller, you have decided to perform a restore operation on
Vikentia [17]

Normally active directory once is corrupted best method is to repair the active directory. As IT administrator user has keep a proper backup either date wise or weekly wise.

<u>Explanation:</u>

If IT administrator doesn’t have enough backup restore or repairing the active directory is highly impossible.

Before restore proper information to be made and rebooted the domino server and selected advance boot option and select the restore options. And select the proper and good backup and restore it. After restoring the backup domain server started and domain active directory should work proper.

As experience better to reinstall domain server and active directory is good practice.

5 0
2 years ago
When a range of IP addresses is set aside for client devices, and one of these IPs is issued to these devices when they request
Pepsi [2]

Answer:

The answer is "Dynamic".

Explanation:

The dynamic allocation of the IP address describes the difference from once in a while, unlike with a static IP address.  

  • In this many residential networks are work on different IP addresses, which requires, and provides clarification.
  • It is also known as an economical, Provides by "ISP" to allocate a dynamic IP address to certain subscribers.
7 0
2 years ago
What is the Gain (dB) of a transmission if the Maximum Data Rate is 1 Gbps and the Bandwidth =7000 MHz? Group of answer choices
denpristay [2]

Answer:

15.420 dB

Explanation:

the Gain (dB) of a transmission if the Maximum Data Rate is 1 Gbps and the Bandwidth =7000 MHz is 15.420 dB.

3 0
2 years ago
Write a flowchart and C code for a program that does the following: Within main(), it asks for the user's annual income. Within
Fiesta28 [93]

Answer:

I am writing a C program:

#include <stdio.h> //to use input output functions

void printIt(double annual_in){ //function printIt

   if(annual_in >90000) //check if the income is greater than 90000

   printf("Congratulations. Doing great!"); //print this message if income value is greater than 90000

   else //if annual income is less than 90000

   printf("You WILL make $50,000, if you keep going"); } //print this message if income value is less than 90000

int main() //start of main() funciton body  

{   double income; //declares a double type variable income to hold annual income value

   printf("Enter annual income: "); //prompts user to enter annual income

   scanf("%lf",&income); //reads income value from user

   printIt(income); } // calls printIt method by passing input income to that function

     

Explanation:

The program is well explained in the comments mentioned with each statement of the program. The flowchart is attached.

First flowchart flow1 has a separate main program flowchart which reads the income and calls printIt function. A second flowchart is of prinIt() method that checks the input income passed by main function and displays the corresponding messages and return.

The second flowchart flow2 is the simple flowchart that simply gives functional description of the C program as flowchart is not where giving function definitions is important. Instead of defining the function printIt separately for this C program, a high-level representation of functional aspects of this program is described in second flowchart while not getting into implementation details.

7 0
2 years ago
Other questions:
  • Wesley has to create a web banner to announce a “Back to School” sale by an online retailer. Which information should he determi
    15·2 answers
  • Read this excerpt from The Outsiders. Or I could have gotten one of the gang to come along, one of the four boys Darry and Soda
    6·2 answers
  • Days of the week are represented as three-letter strings ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"). Write a javaScript f
    14·1 answer
  • Write a class called Counter that represents a simple tally counter, which might be used to count people as they enter a room. T
    9·1 answer
  • Templates contain common layout and formatting that can save you time by not having to recreate documents from scratch. True or
    10·1 answer
  • Write a sequence of statements that create a file named "greeting" and write a single line consisting of "Hello, World!" to that
    5·1 answer
  • Write the definition of a function printAttitude, which has an int parameter and returns nothing. The function prints a message
    14·1 answer
  • Now that the classList Array has been implemented, we need to create methods to access the list items.
    5·1 answer
  • Define a function UpdateTimeWindow() with parameters timeStart, timeEnd, and offsetAmount. Each parameter is of type int. The fu
    13·1 answer
  • A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a fi
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!