Java Programming Task: Use nested for loops statements to draw empty boxes of an
ID: 3667576 • Letter: J
Question
Java Programming
Task: Use nested for loops statements to draw empty boxes of any character (input from user). The boxes have the same number of rows and columns (input from the user; valid range: 5 to 21). Test for errors in input (including type)
SAMPLE OUTPUT:
Do you want to start(Y/N): y
How many chars/last row? n
Not an integer! Try again! How many chars/last row? fgfgfg
Not an integer! Try again! How many chars/last row? 7.6
Not an integer! Try again! How many chars/last row? 34
ERROR! Valid range 5 - 21. How many chars/last row? 7
What character? k
kkkkkkk
k k
k k
k k
k k
k k
kkkkkkk
Do you want to continue(Y/N): y
How many chars/last row? y
Not an integer! Try again! How many chars/last row? 9
What character? #
#########
# #
# #
# #
# #
# #
# #
# #
#########
Do you want to continue(Y/N): n
Explanation / Answer
public static void main(String[] args) { Scanner input = new Scanner(System. in ); char answer = 'n'; int row = 0; char output = 'k'; do { System.out.println("DO YOU WANT TO START Y OR N?"); answer = input.next().charAt(0); System.out.println("enter the number of rows"); while (!input.hasNextInt()) { System.out.println("Not an integer,try again "); input.next(); } row = input.nextInt(); while (row < 5 || row > 21) { System.out.println("ERROR! Valid range 5 - 21. How many chars/last row?"); row = input.nextInt(); } System.out.println("WHAT CHARACTER?"); output = input.next().charAt(0); for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.