Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java please Assignment 4 A: Diamonds in the sky . In our earliest labs, we asked you to print a diamond pattern to the

In java please Assignment4A: Diamonds in the sky.
In our earliest labs, we asked you to print a diamond pattern to the screen using predefined print
statements. Now that we know how to use loops, we can make more dynamic and customizable
patterns.
For this assignment, we will prompt the user to enter a single character and a maximum width
for the diamond. If they enter a number less than 3, we'll prompt them to choose a correct width.
If they enter an even number (greater than 3), we will add 1 to it and let the user know the final
diamond size. Then we will generate and print out the diamond using the user's inputted
character and '' symbols.
Hints: Each line of the "diamond" is made up of two parts - the character in the center
and the spaces to the left of it. The amount of "left space" decreases as we go towards
the middle diamond, then increases afterwards as we go towards the bottom. Could we
use multiple loops (or even nested loops) to model this behavior? Also, note that the
number of characters increases (and later decreases) by two on each line.
Call the file name Assignment4A(.java, .cs,.cpp) and the class name Assignment4A.
User input is indicated in bold
Sample Output #1:
Enter a character to use: +
Enter the diamond's width: 5
+
++
++++
++
+
Sample output #2:
Enter a character to use:
Enter the diamond's width: 8
To make a diamond, we'll use 9 as the width instead.
******
**********
**********k**k
************k**k**
**********k**
**********
******
Sample output #3:
Enter a character to use:
Enter the diamond's width: -2
Please enter a width of at least 3.
Enter the diamond's width: 3
image text in transcribed

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

Students also viewed these Databases questions