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
nataly862011 [7]
3 years ago
8

Write a program that displays the following pattern: ..\.\* .\.\*** \.\***** ******* \.\***** .\.\*** ..\.\* That is, seven line

s of output as follows: The first consists of 3 spaces followed by a star. The second line consists of 2 spaces followed by a 3 stars. The third consists of one space followed by 5 stars, and the fourth consists just of 7 stars. The fifth line is identical to third, the sixth to the second and the seventh to the first. Your program class should be called StarPattern
Computers and Technology
1 answer:
nalin [4]3 years ago
3 0

Answer:

public class StarPattern {

   

   public static final int MAX_ROWS = 7;

   

    public static void main(String []args){

       

       for (int row = 1; row <= MAX_ROWS; row++) {

           int numOfSpaces = getNumberOfSpaces(row);

           int numOfStars = MAX_ROWS - (getNumberOfSpaces(row) * 2);

           String spaces = printSpaces(numOfSpaces);

           String stars = printStars(numOfStars);

           System.out.println(spaces + stars);

       }

       

    }

    public static int getNumberOfSpaces(int row) {

        int rowOffset = (MAX_ROWS / 2) + 1;

        return Math.abs(row-rowOffset);

    }

   

    public static String printSpaces(int num) {

        String result = "";

        for (int i = 0; i < num; i++) {

            result += " ";

        }

        return result;

    }

   

    public static String printStars(int num) {

        String result = "";

        for (int i = 0; i < num; i++) {

            result += "*";

        }

        return result;

    }

}

Explanation:

So it sounds we need to make a diamond shape out of asterisks like this:

  *

 ***

*****

*******

*****

 ***

  *

There are 7 rows and each row has up to 7 characters. The pattern is also symmetrical which makes it easier. Before writing any code, let's figure out how we are going to determine the correct amount of spaces we need to print. There are a lot of ways to do this, but I'll just show one. Let's call the 4th row y=0. Above that we have row 3 which would be y=-1, and below is row 5 which is y=1. With 7 rows, we have y=-3 through y=3. The absolute value of the y value is how many spaces we need.

To determine the number of stars, we just double the number of spaces, then subtract this number from 7. This is because we can imagine that the same amount of spaces that are printed in front of the stars are also after the stars. We don't actually have to print the second set of spaces since it is just white space, but the maximum number of characters in a row is 7, and this formula will always make sure we have 7.

I hope this helps. If you need help understanding any part of the code, jsut let me know.

You might be interested in
A cell reference with only one dollar sign before either the column or the row is called an absolute reference.
BlackZzzverrR [31]
False, absolute references have two dollar signs
4 0
3 years ago
Why is OS important in every data processing system? <br>Please Answer Fast! ​
Artist 52 [7]

Answer:

Functions of an operating system. An operating system provides three essential capabilities: It offers a UI through a CLI or GUI; it launches and manages the application execution; and it identifies and exposes system hardware resources to those applications -- typically, through a standardized API.

Explanation:

6 0
2 years ago
Which of the following does NOT help a user navigate through a document?
FromTheMoon [43]

Answer:

Navigation Tabs

Explanation:

Navigation tab is used to switch between different pages that are shown in navigation tab. It is not used to navigate through the document.

Scroll bar is used to navigate through the document line by line. It has been shown on the right side of the document to move up and down the page.

Next page and previous page button used to navigate between pages of the documents.

7 0
3 years ago
1. A teacher asked a student to capture and print out a one-slide presentation using MSWord,       showing everything on the scr
Drupady [299]

The keyboard combinations that can be used to capture and print out a one-slide presentation using MSWord, showing everything on the screen is Function key + PrtScr

<h3>What is a Key Combination?</h3>

This refers to the procedure that is used to combine two or more keys on the keyboard to execute a task.

Hence, we can see that the procedure that can be used to carry out the operation is:

  • Enter the screen you want to capture and print
  • Press the Function key, followed by the PrtScr. Please note this can vary slightly, depending on the keyboard.

The hardware devices that would be needed to be set up by the system analyst at a computer laboratory are:

  • System Unit
  • Laptops/Monitor
  • Power adapters
  • Ethernet cables, etc

The database applications that can be recommended by the system analyst are:

  • MySQL,
  • SQL Server

The five word processing packages that are likely to be installed are:

  • G00..gle Docs
  • MsWord
  • MSOffice
  • Dropbox Paper
  • Corel WordPerfect

Read more about word processing here:

brainly.com/question/985406

#SPJ1

6 0
2 years ago
Select the correct answer.
aliina [53]

Answer:

B

Explanation:

engineers design and carry out test cases and evaluate exit criteria (by following the scope set in the planning phase). They create bug reports describing detected defects and report to the stakeholders on the test findings and the completion status. Testing may be repeated to check for errors.

7 0
3 years ago
Other questions:
  • When a crystal grows in unrestricted space, how does growth occur?
    14·2 answers
  • Given a positive real number, print its fractional part.
    14·1 answer
  • Which group on the Home Tab allows you to add shapes to a PowerPoint slide?
    9·2 answers
  • Please check my answer! (Java)
    13·1 answer
  • Bytes are typically represented with a lowercase b and bits with an uppercase B.<br> true or false
    7·1 answer
  • Write a function called printBackwards() that will work with a C string. The function will print any C string backwards. You don
    13·1 answer
  • The IBM nine-track tapes that became the industry standard for storage for three decades had several sizes , the most common bei
    13·1 answer
  • Connect 5 LEDs with any random colors. Iteratively, turn ON 1 to 5 LED(s) that will take 5 iterations in total, and in every ite
    6·1 answer
  • Is Filmora 9 or Final Cut Pro Better for personal use?
    12·1 answer
  • Is y0utube an example of unsupervised learning or supervised learning?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!