the making of a pattern | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

the making of a pattern

Help, i dont get the question in my homework. This is the given instruction: If input: 3 5 Output should be: **** * * * * * * * * **** Rectangle Area: 15 Perimeter: 16 Centerpoint: As you see, the length 5 becomes 6, and the width 3 becomes 4. How to do this? And, how do I determine if its rectangle or square? How do I calculate its centerpoint? Below is my code https://code.sololearn.com/c4A25A7a8a22

1st Jul 2021, 12:09 AM
Brianna
1 Answer
+ 1
if you're trying to get your pattern to look like the one in your post, then all you should need to do is change the initialization of i and j in your for loops to 0's instead of 1's, and then change the if statement so that they are also 0's instead of 1's. You can determine if it is a square simply by checking if the inputs are equal to each other (5 x 5). Otherwise, it is a rectangle (3 x 5). System.out.println(rows == columns ? "Square": "Rectangle"); The centerpoint of a rectangle/square is located (base/2, height/2).
1st Jul 2021, 1:10 AM
ChaoticDawg
ChaoticDawg - avatar