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
What is a user interface have? Plz answer ASAP!!!!!
konstantin123 [22]

Put simply, a user interface is the point of human-computer interaction and communication on a device, webpage, or app. This can include display screens, keyboards, a mouse, and the appearance of a desktop.

5 0
3 years ago
Read 2 more answers
Formulas within table cells always begin with
Montano1993 [528]
The answer is C.

Formulas within table cells always begin with an equal sign.

Here is the sample of some of the formulas :

1. Sum (equation)
=SUM(5, 5) or =SUM(A1, B1) or =SUM(A1:B5)

2. Count ( to count number of cells or rows)
=COUNT(A1:A10)

3. Trim ( Get rid of any space in a cell)
=TRIM(A1)

4. Vlookup ( to look up data from a vertically structured table)
=VLOOKUP(lookup_value, table_array, col_index_num, range_lookup)

5. if statements
=IF(logical_statement, return this if logical statement is true, return this if logical statement is false)







5 0
3 years ago
TCP connections are established through sequence numbers. Someone can guess a client's next sequence number and then impersonate
solong [7]

Options: True or false

Answer: True

Explanation:TCP(TRANSMISSION CONTROL PROTOCOL) is is an internet control protocol that allows Communication between internet users or computers by collecting and compiling packets of data and then sending such collected packets of data to the desired user.

Before using a TCP one must first create a connection which will enable it to effectively communicate with the other user.

TCP are established using sequence numbers which can be predicted by another party for their own personal gain.

6 0
3 years ago
¿que lenguaje de programacion usan los operadores matematicos?​
kolbaska11 [484]

Answer:

Matlab / GNU Octave. MATLAB (laboratorio de matrices) es un entorno informático numérico multiparadigma y un lenguaje de programación de cuarta generación.

Explanation:

8 0
3 years ago
Read 2 more answers
List any three importance of computer​
Naddika [18.5K]

Answer:

here is the answer

Explanation:

1) accurate

2) fast

3) can accomplish tasks more effencily

5 0
3 years ago
Other questions:
  • Computer-integrated manufacturing (CIM) includes manufacturing systems that have:
    7·1 answer
  • Hiding an object, such as a diary, to prevent others from finding it is an example of:______________.
    10·1 answer
  • Keep getting the message i failed to sign in to email on my phone but i can open my email. whats going on?
    10·2 answers
  • which is true someone with a low credit score I . they probably make on time payments ll . they may not be able to rent the apar
    14·2 answers
  • Physical activity such as sports or even a brisk walk can help reduce
    7·2 answers
  • On a piano, a key has a frequency, say f0. Each higher key (black or white) has a frequency of f0 * r^n, where n is the distance
    7·1 answer
  • Diane is receiving a lot of unwanted e-mail. What steps can she take to reduce the amount of e-mail she receives?
    12·1 answer
  • A small group of travelers is meeting inside an ancient building, and the travelers need access to the Internet using their mobi
    11·1 answer
  • A simulation system is a technology that enables you to take over a customer’s screen, mouse, or other connected device in order
    13·1 answer
  • Read the following scenario:
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!