Question: Complete the printPattern method in the PatternPrinter class so that the program will print the specified pattern for the given input size. The Pattern: Pattern
Complete the printPattern method in the PatternPrinter class so that the program will print the specified pattern for the given input size.
The Pattern:
| Pattern Size | Pattern | Pattern with Dots in Place of Spaces |
| 3 | * * * * * * * * * | .*.*.* .*.* .* .*.* .* |
| 4 | * * * * * * * * * * * * * * * * | .*.*.*.* .*.*.* .*.* .* .*.*.* .*.* .* |
| 5 | * * * * * * * * * * * * * * * * * * * * * * * * * | .*.*.*.*.* .*.*.*.* .*.*.* .*.* .* .*.*.*.* .*.*.* .*.* .* |
| 6 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | .*.*.*.*.*.* .*.*.*.*.* .*.*.*.* .*.*.* .*.* .* .*.*.*.*.* .*.*.*.* .*.*.* .*.* .* |
Note 1: You do not have to modify the main method of the class. Please do not modify it as it will generate errors in your solution. You should only be implementing the printPattern method.
Note 2: White spaces should be of exact amount for this program. The pattern with spaces replaced with dots "." is also provided for your reference. At the end of printing the pattern, the newline character must be printed exactly once.
We Have this till now,
import java.util.Scanner;
public class PatternPrinter {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); System.out.println("Enter the size of the pattern (Greater than 2):"); int patSize = in.nextInt(); if(patSize > 2) printPattern(patSize); else System.out.println("Invalid Pattern Size!"); in.close(); }
public static void printPattern(int patternSize) { //TODO: Complete this method. } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
