Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA PROGRAMMING public static String textBoxString(int rows, int cols, char c1, char c2) The returned String value, when printed, displays the outline of a rectangle

JAVA PROGRAMMING

public static String textBoxString(int rows, int cols, char c1, char c2)

The returned String value, when printed, displays the outline of a rectangle of rows rows and cols columns using alternating c1 and c2 characters. Note that the first printed character should be c1, and every other printed character should be c1. The second printed character should be c2, and every other printed character should be c2. For example, in the example below, the end of the first line is 'x' and the beginning of the second line is 'o'. The next printed character, at the end of the second line is 'x'.

String s = textBoxString(3, 5, 'x', 'o'); System.out.println(s); will print

xoxox

o x

oxoxo

This is what I have so far:

public static String textBoxString(int rows, int cols, char c1, char c2) { String result1 = ""; for (int i = 1; i <= rows; i++) { if (i % 2 == 0) { // if the row is even (row 2) for (int j = 1; j <= cols; j++) { if ( i == 1 || i == rows || j == 1 || j == cols) { if (j % 2 == 0) { result1 += c1; // print"x" for the even column } else { result1 += c2; // print "o" for the odd column } } }result1 += " "; // go to next line } else { // if the row is odd (row 1 and 3) for (int j = 1; j <= cols; j++) { if ( i == 1 || i == rows || j == 1 || j == cols) { if (j % 2 == 0) { result1 += c2; // print "O" for the even column } else { result1 += c1; // print "x" for the odd column } } }result1 += " "; } } return result1; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students also viewed these Databases questions

Question

Were they made on a timely basis?

Answered: 1 week ago

Question

Did the decisions need to be made, or had they already been made?

Answered: 1 week ago

Question

When there was controversy, was it clear who had the final say?

Answered: 1 week ago