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
Stells [14]
2 years ago
15

Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if

the side length is 4, the program should display[a diamond with the middle having 7 asterisks]
*

***

*****

*******

*****

***

*

Computers and Technology
2 answers:
vazorg [7]2 years ago
8 0

Answer:

side = int(input("Please input side length of diamond: "))

# for loop that loop from 0 to n - 1

for i in range(side-1):

   # inside the print statement we determine the number of space to print

   # using n - 1 and repeat the space

   # we also determine the number of asterisk to print on a line

   # using 2 * i + 1

   print((side-i) * ' ' + (2*i+1) * '*')

# for loop that loop from 0 to n - 1 in reversed way

for i in range(side-1, -1, -1):

   # this print statement display the lower half of the diamond

   # it uses the same computation as the first for loop

   print((side-i) * ' ' + (2*i+1) * '*')

Explanation:

The program is written in Python and well commented. The first for loop display the first half of the diamond while the second for loop display the lower half.

A screenshot of program output when the code is executed is attached.

zaharov [31]2 years ago
3 0

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        int n = input.nextInt();
  6.        int l = 1;
  7.        for(int i=1; i <= n; i++){
  8.            for(int j=1; j<= l; j++){
  9.                System.out.print("*");
  10.            }
  11.            System.out.println();
  12.            l = l + 2;
  13.        }
  14.        l = l - 4;
  15.        for(int i=1; i < n; i++){
  16.            for(int j=1; j <= l; j++){
  17.                System.out.print("*");
  18.            }
  19.            System.out.println();
  20.            l = l-2;
  21.        }
  22.    }
  23. }

Explanation:

The solution code is written in Java.

Firstly use a Scanner object to accept an input integer (Line 5-6).

Create the first set of inner loops to print the upper part of the diamond shape (Line 8-14). The variable l is to set the limit number of asterisk to be printed in each row.

Next, create another inner loops to print the lower part of the diamond shape (Line 17-23). The same variable l is used to set the limit number of asterisk to be printed in each row.

You might be interested in
A computer’s memory is composed of 8K words of 32 bits each. How many bits are required for memory addressing if the smallest ad
victus00 [196]

Answer:

The minimum number of bits necessary to address 8K words is 13.

Explanation:

You have the number of words to address that is 8000 words, a word is the smallest addressable memory unit.  

8000 words can be addressed with 2^{n}  units. Now you have to find the value of n that approximates to the number of words.  

2^2=4\\2^4=16\\2^7=128\\2^{10}=1024\\2^{12}=4096\\2^{13}=8192

So you can see that 13 bits are needed to address 8K words.

7 0
2 years ago
We Deliver trains its truck loaders how to set the packages in the delivery vehicles, so that when delivery drivers are pulling
damaskus [11]

Answer:

We Deliver trains its truck loaders how to set the packages in the delivery vehicles, so that when delivery drivers are pulling packages off their trucks, they are organized in a specific order and with the label facing forward to reduce errors and save time. A <u>Procedure </u>is being implemented when directing that the trucks be loaded in this specific manner.

Explanation:

Procedure is the method or set of instructions to perform some operation in specific order to complete the task in an organized manner. It is the type of directions to perform some operations.

In above mentioned case, if we want that the packages should set in some organized manner such as labeling face of package in forward direction so that, chance of error should reduce and time save. We should provide some procedure to the truck loaders.

5 0
2 years ago
The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet class and includes a private fi
Lapatulllka [165]

Answer:

Hello attached is the Java program written to solve the problem

The Pet.java and Dog.java files are unaltered

Explanation:

The input and output  codes are attached as well i.e the second image is the input while the third image is the output code

5 0
2 years ago
Brake lights on freeways invite A: law enforcement B: panic C: sudden lane changing D: both B and C E: positive driving habits
Nuetrik [128]
I'am sorry i'am speak spanish

8 0
2 years ago
Brittany just pulled up a database table with employee information that contains 50 records of employees at her company. Which o
lesantik [10]

Answer:

The answer is: Operations.

Explanation:

A database operation accesses to information of a relational database. In this case, Brittany has creates the database operation that select employee information of her company and the database has returned a result set. The SQL statement to perform operations on a database are:

  • INSERT
  • SELECT
  • UPDATE
  • DELETE

3 0
2 years ago
Other questions:
  • In a system containing CPU 1 and Disk Drive A, the system is instructed to access Track 1, Track 9, Track 1, and then Track 9 of
    12·1 answer
  • Initialize the list short_names with strings 'Gus', 'Bob', and 'Zoe'. Sample output for the givenprogram:Gus Bob Zoeshort_names
    13·1 answer
  • Question 1 :Which type of unshielded twisted pair (UTP) cable is commonly used for 1000BASE-T Ethernet networks and is often mad
    8·1 answer
  • Suppose that we have a set of activities to schedule among a large number of lecture halls, where any activity can take place in
    8·1 answer
  • Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
    12·1 answer
  • Your project must satisfy the following requirements:
    7·1 answer
  • Joe, Kate and Jody are members of the same family. Kate is 5 years older than Joe. Jody is 6 years older than Kate . The sum of
    11·2 answers
  • Java Programming home &gt; 1.14: zylab training: Interleaved input/output Н zyBooks catalog Try submitting it for grading (click
    6·1 answer
  • Calvin is an aspiring graphic designer. He wants to achieve Adobe Certified Expert certification in software that will be helpfu
    9·1 answer
  • c Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just one statement. Hint: Call FindMax() twice in a
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!