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
Write a script named numberlines.py. This script creates a program listing from a source program. This script should: Prompt the
ddd [48]

Answer:

See explaination for program code.

Explanation:

inputFileName = input("Input filename: ") outputFileName = input("Output filename: ") inputFile = open(inputFileName, "r") outputFile = open(outputFileName, "w") count = 1 for line in inputFile: newLine = str(count).rjust(4, " ") + "> " + line outputFile.write(newLine) print(newLine) count += 1

4 0
2 years ago
Which data type stores images and audio visual clips?
Xelga [282]
It could be a 
<span> common settings</span>







4 0
2 years ago
Directions
DanielleElmas [232]

Answer:

is he project for me

Explanation:

3 0
1 year ago
A colleague sent you an awesome article about using proper ergonomics while sitting at the computer. You don't have time to read
lys-0071 [83]

Answer: Select the article attachment and save it to your computer.

Explanation:

5 0
2 years ago
Which of the following is not an advantage of a flowchart?
ad-work [718]

Answer:

d) Improper documentation

Explanation:

A flowchart is a type of diagram in which it presents the flow of the work or how the process is to be followed. It is a diagram that represents an algorithm that defines step by step approach to solving the task. In this, there are various boxes that are linked with the arrows

There are various advantages like in this, there is a better communication, coding is to be done in an efficient way, system could be tested also there is a proper documentation

hence, the correct option is d

4 0
2 years ago
Other questions:
  • A(n) ____ is an electronic device, operating under the control of instructions stored in its own memory, that can accept data, p
    14·1 answer
  • Choose all items that represent characteristics of a work samples.
    8·2 answers
  • Which are methods used to improve reading fluency? Check all that apply. Practicing with a weak reader listening to a fluent rea
    5·2 answers
  • Describe a situation involving making a copy of a computer program or an entertainment file of some sort for which you think it
    7·1 answer
  • The term Electronic Privacy Information Center (EPIC) refers to a form of the digital subscriber line technology, which enables
    6·1 answer
  • Consider the following 3-PARTITION problem. Given integers a1; : : : ; an, we want to determine whether it is possible to partit
    10·1 answer
  • Design and implement an algorithm that gets as input a list of k integer values N1, N2,..., Nk as well as a special value SUM. Y
    12·1 answer
  • Explain working principle of computer?​
    13·1 answer
  • To reduce costs and the environmental impact of commuting, your company decides to close a number of offices and to provide supp
    14·1 answer
  • Consider a disk that rotates at 3600 rpm. The seek time to move the head between adjacent tracks is 2 ms. There are 32 sectors p
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!