Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display

Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character X. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following: XXXXX XXXXX XXXXX XXXXX XXXXX

INPUT and PROMPTS. The program prompts for an integer as follows: "Enter an integer in the range of 1-15: ".

OUTPUT . The output should be a square of X characters as described above.

CLASS NAMES. Your program class should be called SquareDisplay

What is the problem with this code....error messages received: all the way up to java 23 with error message.

SquareDisplay.java:1: error: class, interface, or enum expected public static void main(String[] args) { ^ SquareDisplay.java:2: error: illegal character: '\u00a0' Scanner keyboard = new Scanner(System.in); ^ SquareDisplay.java:2: error: illegal character: '\u00a0' Scanner keyboard = new Scanner(System.in); ^ SquareDisplay.java:2: error: illegal character: '\u00a0' Scanner keyboard = new Scanner(System.in); ^ SquareDisplay.java:3: error: illegal character: '\u00a0' System.out.print("Enter a number between 1-15: "); ^ SquareDisplay.java:3: error: illegal character: '\u00a0' System.out.print("Enter a number between 1-15: "); ^ SquareDisplay.java:3: error: illegal character: '\u00a0' System.out.print("Enter a number between 1-15: "); ^ SquareDisplay.java:3: error: class, interface, or enum expected System.out.print("Enter a number between 1-15: "); ^ SquareDisplay.java:4: error: illegal character: '\u00a0' int number = keyboard.nextInt(); ^ SquareDisplay.java:4: error: illegal character: '\u00a0' int number = keyboard.nextInt(); ^ SquareDisplay.java:4: error: illegal character: '\u00a0' int number = keyboard.nextInt(); ^ SquareDisplay.java:4: error: class, interface, or enum expected

Program below:

public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter a number between 1-15: "); int number = keyboard.nextInt(); validateNumber(keyboard, number); outputMatrix("X", number); keyboard.close(); } static void validateNumber(Scanner keyboard, int number) { while (number < 1 || number > 15) { System.out.println("Sorry, that's an invalid number."); System.out.print("Enter an integer in the range of 1-15: "); number = keyboard.nextInt(); } } static void outputMatrix(String charToOutput, int number) { for (int row = 0; row < number; row++) { for (int column = 0; column < number; column++) { System.out.print(charToOutput); } System.out.println(); } }

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

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago

Question

Write short notes on Marketing mix.

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago