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
I need help solving this problem on Picoctf. The question is What happens if you have a small exponent? There is a twist though,
soldi70 [24.7K]

Explanation:

Explanation:

RSA encryption is performed by calculating C=M^e(mod n).

However, if n is much larger than e (as is the case here), and if the message is not too long (i.e. small M), then M^e(mod n) == M^e and therefore M can be found by calculating the e-th root of C.

5 0
3 years ago
1. Write a generic method that compares its 2 arguments using the equals method and returns true if they are equal and false oth
Ganezh [65]

Answer:

Explanation:

The following piece of code is written in Java. It creates the method as requested that takes in two generic objects and compares them using the .equals() built in Java method. This method will return True if the objects are identical or False if they are not. A test case is used in the code and the output can be seen in the attached image below.

   public static <T> boolean comparePerez(T a, T b) {

       return a.equals(b);

   }

5 0
3 years ago
what's the best mouse for fast clicking ? I play a lot of fps and a lot of pvp games I need a mouse that I can click fast with a
kondaur [170]
Alenware hp dell logtech, and i know others
7 0
3 years ago
List and describe 3 parts (often referred to as 'elements') of a web page?
Art [367]

Answer:

Content

Design

Development

Explanation:

The design and management of sites is internet explorer; it is the research that takes place over time to make a site look fantastic, work quickly and function well with a smooth user interface.

7 0
3 years ago
V to "mutual funds"?
Anettt [7]

Answer:

D. All of the above.

Explanation:

The mutual funds can be affected by the market condition, and the investor's investment can be lost. It does not provide any assurance or any guarantee that the scheme targets or the goals are going to be achieved or will not be achieved. The investment of the fund is done later, and businesses are picked up according to the wishes of the investor who creates the pool.

And they can be a smart investment for young people, and they do contain the combination of various types of stocks. And they are commonly found in the retirement accounts. Hence, all of the above points are true about mutual funds.

3 0
3 years ago
Other questions:
  • Helen has no experience in security. She would like to earn a certification that demonstrates that she has the basic knowledge n
    15·1 answer
  • A variation of pronounce is a. Proclaim c. Produce b. Profound d. Pronunciation Please select the best answer from the choices p
    11·1 answer
  • What activities are the most likely to infect your computer vith a virus? Check all that apply.
    10·1 answer
  • How Can I add a image in an HTML program?​ please tell
    6·1 answer
  • What are the tyoe of typical application of mainframe computer<br>​
    6·1 answer
  • How are satellite radio, Internet radio, and podcasting different?
    11·1 answer
  • PLEASE HELP ITS TIMED Ishmael would like to capture a selected portion of his screen and then capture actions he performs on tha
    8·1 answer
  • Of the following field which would be the most appropriate for the primary key in a customer information table?
    5·1 answer
  • Which keyboard shortcut cuts information to the clipboard?
    14·1 answer
  • What tv show inspired the term spam for junk email?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!