1. Engineering
  2. Computer Science
  3. prints the following pattern for n 10 ...

Question: prints the following pattern for n 10 ...

Question details

Prints the following pattern for n = 10:

       * * * * * * * * * *
       * * * * * * * *
       * * * * * *
       * * * *
       * *
       * *
       * * * *
       * * * * * *
       * * * * * * * *
       * * * * * * * * * *

IN JAVA: Create a method that RETURNS A STRING PATTERN of a “triangular square” with N lines. For this problem, describing the desired result is difficult, so instead I provided two examples of what the method should return. To help you understand the construction of the “triangular square”, imagine a vertical line that splits the square into a left- and right- half. You can see that the two halves are mirror images of each other. Pay attention to the number of stars and spaces on either side of the line. Come up with a rule (ie, “for line N, there are x stars and y spaces”) and then implement that. Note: The method has to follow the outline I have provided below and it cannot be a void method. It needs a return statement, and it has to return a string.




      
       Prints the following pattern for n = 11:
      
       * * * * * * * * * *
       * * * * * * * *
       * * * * * *
       * * * *
       * *
      
       * *
       * * * *
       * * * * * *
       * * * * * * * *
       * * * * * * * * * *
  


   public String printPattern(int n) {
       // Write code here
       return something;
   }

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution