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
The ____ file is typically saved with a prefix of inc_.
KonstantinChe [14]

The include file is typically saved with a prefix of inc_.

<h3>What is include file?</h3>

The include (or require ) statement is known to be one that often takes the total text/code/markup that is seen in the specified file and it is one that copies it into a given file that uses what we call the include statement.

A file is known to be any form of documents and it is one that can be in any format such as pdf, doc and others.

Hence, in the case above, The include file is typically saved with a prefix of inc_ as that is the way to save it.

Learn more about file from

brainly.com/question/26125959

#SPJ1

5 0
2 years ago
Select the correct answer.
tia_tia [17]

Answer:

A

Explanation:

HTML is a coding language.

8 0
3 years ago
Input two numbers and work out their sim, subtraction, multiplication, division, remainder, average and sum of the squares of th
nadezda [96]

def ultimate_math (num1, num2):

try:

array_num = [num1, num2]

print (num1 + num2)

print (num1 - num2)

print (num1 * num2)

print (num1 / num2)

print (num1 % num2)

print ((num1 + num2) / (len(array_num)))

print ((num1**2) + (num2**2))

except ValueError:

return "Invalid Input"

user_num1 = float (input (" Please enter a num: "))

user_num2 = float (input (" Please enter a second num: "))

print (ultimate_math (user_num1, user_num2))

5 0
3 years ago
Which data type is 1.2e3?
Alexxandr [17]

Answer:

Float, Floating point numbers go up to 3.402823466 E + 38

Explanation:

7 0
3 years ago
What is the name of the tab that becomes available after you add and select an image in your PowerPoint presentation?
ArbitrLikvidat [17]

Answer:

INSERT

Explanation:

INSERT PCIURE

7 0
3 years ago
Other questions:
  • What is the outlined area called?
    6·1 answer
  • What IEEE 802.11 wireless standard supports devices only in the 5GHz range with speeds up to 4.9Gb/s because of accepting data f
    12·1 answer
  • What do the points on this website do?
    14·2 answers
  • There are some practices that result in discrimination but may not look discriminatory at first glance. If a company only hires
    15·1 answer
  • On the Header &amp; Footer Tools Design tab, you can conveniently add a header, a footer, page numbers, and A. columns. B. times
    8·2 answers
  • The video game machines at your local arcade output coupons depending upon how well you play the game. You can redeem 10 coupons
    14·1 answer
  • __________ is the order of arrangement of files and folders.
    6·1 answer
  • Through the use of computational thinking techniques, models and algorithms can be created. A(n) ___1___ can be created that rep
    12·2 answers
  • What is role can ICT play in helping school take part in social responsibility
    14·1 answer
  • One symptom of malware infection is that your antivirus software is disabled and cannot be re-enabled. Choose the answer. True F
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!