Question
For the solution, use the StarPattern class you added to the project. That is, public class StarPattern { public static void main(String[] args) { //
For the solution, use the StarPattern class you added to the project. That is,
-
public class StarPattern {
public static void main(String[] args) { // TODO Auto-generated method stub
} }
-
In the body of the main method, declare a single String class type variable named pattern.
-
The pattern will hold the address of a String object with a string literal as its value, which is needed to be created in 4.
-
The string value is a description of the star pattern given in 1. Write this description using the *, the space character, and (new line character) as many times as needed as a string value.
-
(a) Use String class length method to print the length of the obtained pattern in 4. The length of this pattern is the total number of the characters used in constructing this pattern.
-
(b) Then print the star pattern from the string value which is constructed in 4. Use a single print statement that prints pattern to the console; that is, you are not allowed to use System.out.println repeatedly to print the given star pattern line by line. The result of this print statement will display a star pattern as shown in 1.
-
Use JOptionPane class showMessageDialog method to complete the same tasks as 5 above. Display the length of the pattern and the star pattern, as shown in Figure 3. When you use JOptionPane class, you are required to have the following import for JOptionPane class to be placed before the comment block of 3. in the Preliminaries section.
import javax.swing.JOptionPane; //required for JOptionPane class. Before the end of the main method, you are required to have System.exit(0); //required for JOptionPane class.
-
Run your program to see if the pattern appears correctly. Remove errors and make corrections as necessary in 4. That means, you must have the correct number of the occurrences for the *s with spaces and s in a string literal. Repeat this until you have the star pattern displayed correctly to both the console and then the message dialog boxes.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started