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]
2 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]2 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
Lydia used software to calculate the budget for each department. To create this budget, she used a _____.
Ann [662]
Lydia used software to calculate the budget for each department. To create this budget, she used a spreadsheet.
4 0
3 years ago
Read 2 more answers
6 The part of the computer that contains the brain or central processing unit is also known as the ?
Olin [163]
Answer:  "CPU" .
________________________________
4 0
3 years ago
The ---------------initiates a message by encoding theidea (or a thought) in words or symbols and sends it to areceiver.ChannelS
saw5 [17]

Answer:

None of the given options

Explanation:

The sender initiates a message by encoding theidea (or a thought) in words or symbols and sends it to a receiver.

8 0
2 years ago
Answer the following questions for Web browser and Web server software: 1. What functions should this software application provi
timurjin [86]

Answer:

Explanation:

Functions should a software application provide to keep a web browser secured

1) The web browser should always be updated, so kindly keep the "automatic update" option enable on your browser settings so that whenever the browser gets an update, it will be updated automatically.

2) Always keep the third party cookies disabled because there are so many unauthorized and phishing sites over the internet they may lead the browser unsafe and cause very higher security risk so block all the third party sites and cookies from the browser

Functions should a software application prohibit to keep a web browser secured

1) Do not store passwords on your web browser, deny the "store password" option on your browser settings. Even if you store passwords on your web browser do set a very strong master password to access all the stored passwords.

2) Do not click on unwanted, unknown hyperlinks. There will be many unsolicited attachments, PDFs, DOCs, files, etc over the internet so do not open or download it unnecessarily.

Functions should a software application provide to keep a web server secured

1) Always use an application scanner. Whenever you install or download any new applications do scan the application before accessing it.

2) Install all the security patches because there are more number of hackers over the internet so do not deny installing the security patcheds on time.  

Functions should a software application prohibit to keep a web server secured

1) When an application is not in use for long time, better uninstall it because they are actually of no use so do uninstall all the unwanted softwares or applications along with extensions.

2) There may be scripts, files, setups, codes stored on the web server unknowingly so do check it and delete all the sample scripts, files and codes from the web server.

5 0
3 years ago
An asymmetric encryption system utilizes how many keys?
ivanzaharov [21]
Two. One for encryption, and one for decryption. RSA is an example of an asymmetric encryption algorithm.
7 0
3 years ago
Other questions:
  • How could the provisions in the new health reform bill improve access to care?
    14·1 answer
  • What is the oldest and most common technique to differentiate information systems?
    8·1 answer
  • An _________ is a phrase formed from the first letters of words in a set phrase or series of words a. Acronymic sentence c. Basi
    7·2 answers
  • Suppose you want to delete an existing file from within Word. What would you do? A. Click on the File button, choose Recent, ope
    9·1 answer
  • A serialized object is ________. an object represented as a sequence of bytes used to store the object's data in a file an objec
    5·2 answers
  • What is the formula equivalent to the function =SUM(B1:B5)? A. =B1+B5 B. =$B$1+$B$5 C. =B1+B2+B3+B4+B5 D. =$B$1+$B$2+$B$3+$B$4+$
    7·1 answer
  • Write a program that reads from a file called dictionary.txt which contains pairs of English and translated words separated by a
    12·1 answer
  • Which of the following bit patterns represents the value -9 in two’s complement notation?
    15·1 answer
  • When an application contains just one version of a method, you can call the method using a(n) ____ of the correct data type.
    6·1 answer
  • What are the three main elements common to all radio ads?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!