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
When I click on someone who asked a question and i want to see there answer it is always blurred and when I asked a question I c
yuradex [85]

Answer:

If your on pc like me use ad blocker I do that but otherwise watch the add press ok after if it dosemt work tell me I’ll try and find you it and for ad blocker you also can have a jailbreak divice and to get and blocker go to chrome extension website search up pop up ad blocker

Explanation:

7 0
3 years ago
a password to a certain database consists of digits that cannot be repeated. if the password is known to consist of at least 8 d
BaLLatris [955]

Answer:

\frac{10!}{2}mins

Explanation:

12 seconds to try one combination will be equivalent to  \frac{1}{12}\times 60 = \frac{1}{5} \ mins

Password contain at least 8 digit i.e. password can contain 8, 9, 10 digit.

Password cannot contain more than 10 digit because it will give room for repetition which it is clearly stated that digit cannot be repeated.

Possible digit that can be used: 9,8,7,6,5,4,3,2,1,0.

Total number of passwords combination possible for each position in 8 digit.

1st position = 10, 2nd position = 9, 3rd position = 8, 4th position = 7, 5th position = 6, 6th position = 5, 7th position = 4, 8th position = 3. Total number of passwords combination possible in 8 digit is equivalent to \frac{10!}{2}.

Total number of passwords combination possible for each position in 9 digit.  

1st position = 10, 2nd position = 9, 3rd position = 8, 4th position = 7, 5th position = 6, 6th position = 5, 7th position = 4, 8th position = 3, 9th position = 2. Total number of passwords combination possible in 9 digit is equivalent to \frac{10!}{1}.

Total number of passwords combination possible for each position in 10 digit.

1st position = 10, 2nd position = 9, 3rd position = 8, 4th position = 7, 5th position = 6, 6th position = 5, 7th position = 4, 8th position = 3, 9th position = 2, 10th position = 1.  Total number of passwords combination possible in 10 digit is equivalent to 10!.

Adding them up and multiplying by  \frac{1}{5} \ mins  to get the total number of time needed to guarantee access to database =  [\frac{10!}{2}\times\ \frac{10!}{1} \times 10!] \frac{1}{5}\ mins = \frac{10!}{2}

7 0
3 years ago
What day Coronavirus will be over?
pashok25 [27]

Answer:

w dont know

Explanation:

3 0
3 years ago
Read 2 more answers
How is unemployment rate in America ?
bekas [8.4K]

Answer:

today it's past 20% and over 30mil jobs lost, but this is mostly due to the coronavirus and not an average of the united states economy

7 0
3 years ago
Read 2 more answers
Now write a program named GreenvilleRevenue that prompts a user for the number of contestants entered in last year’s competition
ss7ja [257]

Answer:

The c# program is given below.

using System;

class GreenvilleRevenue  

{

   static void Main() {

       // variable declared and initialized simultaneously

       int fees = 25;

       int last, present, rev;

       Console.WriteLine( "Enter the number of contestants participating in last year’s competition " );

       last = Convert.ToInt32(Console.ReadLine());

       Console.WriteLine( "Enter the number of contestants participating in this year’s competition " );

       present = Convert.ToInt32(Console.ReadLine());

       Console.WriteLine( "Number of Participants in last year's competition  \t\t" + last);

       Console.WriteLine( "Number of Participants in present year's competition   \t" + present);

       rev = present*fees;

       Console.WriteLine( "Revenue expected in this year’s competition is \t\t\t$" + rev );

       if(last < present)

           Console.WriteLine( "Participants are more this year" );

       else if(last > present)

           Console.WriteLine( "Participants are less this year" );

       else if(last == present)

           Console.WriteLine( "Participants are same both years" );

   }

}  

OUTPUT

Enter the number of contestants participating in last year’s competition  

111

Enter the number of contestants participating in this year’s competition  

123

Number of Participants in last year's competition    111

Number of Participants in present year's competition    123

Revenue expected in this year’s competition is   $3075

Participants are more this year

Explanation:

This program takes input from the user. The input is not validated as this is not mentioned in the question.

1. An integer variable is declared and initialized by the fees of this year’s competition.

2. Integer variables are declared to store participants for last year, present year and revenue earned in the present year.

3. User enters the number of participants in last year’s competition.

4. User enters the number of participants in this year’s competition.

5. All the input from the user is displayed.

6. The revenue earned in this year’s competition is computed and displayed.

7. The message is also displayed whether number of participants this year is greater or not than the last year.

8. Also, if participants are same in both years, the message is displayed accordingly.

6 0
3 years ago
Other questions:
  • Fair use allows individuals to break copyright so long as they ________.
    15·1 answer
  • IN THE MOVIE BACK TO THE FUTURE 1985 IS 1985 THE PUBLICATION DATE?WHERE CAN I FIND THE MOVIE?
    6·1 answer
  • Alright, don't judge me, this is a question that involves my Childhood game PvZ GW 2. So I noticed mods and stuff that get uploa
    12·2 answers
  • A BufferedReader has a constructor that takes a single InputStreamReader parameter. InputStreamReader has a constructor that tak
    8·1 answer
  • When comparing different biometric systems, one of the most important metrics used is called the _________, which represents the
    14·1 answer
  • A garments manufacturing company buys various types of natural and synthetic materials to produce clothes. Which material is a s
    6·2 answers
  • Which graphic file format is used for commercial purposes.
    10·1 answer
  • What is the answer only right answers<br>​
    7·2 answers
  • Which contact field is used to control the name that would appear in the To field of an email message when a user is sending a m
    5·2 answers
  • Windows is a GUI Operating System, what is the other type?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!