First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).Then create a new Java application called "PatternMaker" (without the quotation marks) according to the following guidelines.The program prompts the user for five input values:An integer value between 1 and 10 (inclusive) for the number of rows to be printedA second integer value between 1 and 10 (inclusive) for the number of columns to be printedA string value for the starting string of the patternA string value for the second string of the patternA string value that separates the first two stringsThe program must use nested for loops to print a rectangular array of alternating first and second strings of the pattern, separated by the separator string and such that the first string in the first row uses the "first string" provided by the user, but each subsequent row alternates the starting string between the "second string" the user provided and the "first string" the user provided.So, for instance, if the user enters 5 for the number of rows, 7 for the number of columns, and "XX" for the first string, "OO" for the second string, and "***" for the separator, your program should print the following rectangular pattern.XX***OO***XX***OO***XX***OO***XXOO***XX***OO***XX***OO***XX***OOXX***OO***XX***OO***XX***OO***XXOO***XX***OO***XX***OO***XX***OOXX***OO***XX***OO***XX***OO***XXThoughtsNote the requirement for this program to use nested for loops (Horstmann section 4.3).Note that there is no delimiter at the end of the lines.The logic needed for the nested for loops is a bit tricky. Try writing out the logic for simple cases (e.g., 2 rows and 3 columns).Include multiple runs of this program using a variety of values for the three input strings. Copy and paste all of your sample runs in your source code as a block comment at the bottom below the closing curly brace.

Question
Asked Oct 17, 2019
169 views

First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).

Then create a new Java application called "PatternMaker" (without the quotation marks) according to the following guidelines.

The program prompts the user for five input values:

  1. An integer value between 1 and 10 (inclusive) for the number of rows to be printed
  2. A second integer value between 1 and 10 (inclusive) for the number of columns to be printed
  3. A string value for the starting string of the pattern
  4. A string value for the second string of the pattern
  5. A string value that separates the first two strings

The program must use nested for loops to print a rectangular array of alternating first and second strings of the pattern, separated by the separator string and such that the first string in the first row uses the "first string" provided by the user, but each subsequent row alternates the starting string between the "second string" the user provided and the "first string" the user provided.

So, for instance, if the user enters 5 for the number of rows7 for the number of columns, and "XX" for the first string, "OO" for the second string, and "***" for the separator, your program should print the following rectangular pattern.

XX***OO***XX***OO***XX***OO***XX

OO***XX***OO***XX***OO***XX***OO

XX***OO***XX***OO***XX***OO***XX

OO***XX***OO***XX***OO***XX***OO

XX***OO***XX***OO***XX***OO***XX

Thoughts

  • Note the requirement for this program to use nested for loops (Horstmann section 4.3).
  • Note that there is no delimiter at the end of the lines.
  • The logic needed for the nested for loops is a bit tricky. Try writing out the logic for simple cases (e.g., 2 rows and 3 columns).

Include multiple runs of this program using a variety of values for the three input strings. 
Copy and paste all of your sample runs in your source code as a block comment at the bottom below the closing curly brace.

check_circle

Expert Answer

Step 1

Program:

import java.util.Scanner;

 

public class PatternMaker

{

    public static void main(String[] args)

    {

        int row,column;

        boolean flag = true;

        String first,second,separator;

        Scanner inp = new Scanner(System.in);

 

        System.out.println("Enter number of rows: ");

        row = inp.nextInt();

        System.out.println("Enter number of columns: ");

        column = inp.nextInt();

        System.out.println("Enter first string: ");

        first = inp.next();

        System.out.println("Enter second string: ");

        second = inp.next();

        System.out.println("Enter separator: ");

        separator = inp.next();

 

        for(int x = 0; x < row; x++)

        {

            for(int y = 0; y < column; y++)

            {

                if(flag)

                {

                    System.out.print(first);

                    flag = false;

                }

                else

                {

                    System.out.print(second);

                    flag = true;

                }

                if(y != column-1)

                System.out.print(separator);

            }

            System.out.println("");

        }

    }

 

}

Step 2

Sample Output 1:

fullscreen
Step 3

Sample Output 2:

 

 ...

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: public static int createMirror(String str) write your code to calculate the number of characters tha...

A: A Java program is created to calculate the number of characters to be removed from a string to make ...

question_answer

Q: Question 3: Declare a vector with... a) An empty vector holding int elements b) A vector with size 3...

A:  Declaring the vector:a) Empty vector holding “int” elements:vector&lt;int&gt; intVector;Here, “intV...

question_answer

Q: What are the risks associated with a pervasive security infrastructure? What are the reasons for NOT...

A: Pervasive security infrastructure refers to cloud security risks. As many users possibly from differ...

question_answer

Q: Python 3.7.4 Given four files named asiasales2009.txt, europesales2009.txt, africasales2009.txt, and...

A: Statements for creating objects:#for first file asiasales2009.txt for writingasia = open("asiasales2...

question_answer

Q: Provide a situation that encompasses Integrity in the CIA triad

A: DefinitionIntegrity plays the foremost role in CIA triad. It is designed to secure the data from an ...

question_answer

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: Launch the NetBeans IDE.

question_answer

Q: Write an application starting with ProjectTemplate. Name the class AgeCalcApp. The app needs to prom...

A: To write an application name ProjectTemplate with the class name AgeCalcApp. This application prompt...

question_answer

Q: Problem 1 consists of multiple parts. You should finish one part and ensure that it works before mov...

A: Hello. Since your question has multiple sub-parts, we will solve first three sub-parts for you. If y...

question_answer

Q: Using the following truth table, write the equivalent Boolean equations in Sum of Product and Produc...

A: Simplification of Sum Of Products (SOP):The truth table of the SOP is as follows