Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 5 1115 3 115 2 113 15 3 112 1315 411 22315 143 12213 15 4 122 1423 15 3 13 2 1 3

image text in transcribedimage text in transcribed

1 5 1115 3 115 2 113 15 3 112 1315 411 22315 143 12213 15 4 122 1423 15 3 13 2 1 3 24 15 3 1 22 33 14 15 3 1 22 33 14 15 The digits 1, 2, 3, 4, and 5 were used In this part of the assignment, you are to write a java program that reads a single integer from standard input. Upon reading this single integer, your program should check to see if the value entered is actually an integer, if not, then print an error and exit. If it is an integer, your program should make sure that the number is actually positive single digit, if not then print another error and exit the program. After you read the number, then you should read another positive integer representing the number of lines to print. Again you should error-check for invalid input. Once the correct single positive digit and the number of lines are entered, then the program shoulod display the digit on the screen to start printing a pyramid of digit combinations that counts the number of each digit in the previous line. The format of each line starting with line 2 of the pyramid would be the number of times a digit showed up in the previous line, followed by a space, followed by the digit. These counts are also separated by a space. The pyramid should be formatted like a pyramid which is centered in the screen, not left justified or right justified. You should continue producing lines until one or more of the following conditions happens: 1. You have used all 9 digits in the output. So you need to keep track of which digits you used. This is may not happen by the way, but check for it any way You have produced the required number of lines. You produced the exact line as the one above it (see the example below). 2. 3. Once one or more of the above conditions stops printing the lines, then you should print a message showing which digits were used in the output. Look at the following example: This is a scenario of your program running. Please enter a positive digit: S Please enter the number of lines in the pyramid: 20 The following is the produced pyramid: 15 1115 3115 2 113 15 3 1121315 41122315 1431221315 4 1221 42315 3 13 2132415 3 12 2331415 3 122331415 The digits 1, 2, 3, 4, and 5 were used. 1 5 1115 3 115 2 113 15 3 112 1315 411 22315 143 12213 15 4 122 1423 15 3 13 2 1 3 24 15 3 1 22 33 14 15 3 1 22 33 14 15 The digits 1, 2, 3, 4, and 5 were used In this part of the assignment, you are to write a java program that reads a single integer from standard input. Upon reading this single integer, your program should check to see if the value entered is actually an integer, if not, then print an error and exit. If it is an integer, your program should make sure that the number is actually positive single digit, if not then print another error and exit the program. After you read the number, then you should read another positive integer representing the number of lines to print. Again you should error-check for invalid input. Once the correct single positive digit and the number of lines are entered, then the program shoulod display the digit on the screen to start printing a pyramid of digit combinations that counts the number of each digit in the previous line. The format of each line starting with line 2 of the pyramid would be the number of times a digit showed up in the previous line, followed by a space, followed by the digit. These counts are also separated by a space. The pyramid should be formatted like a pyramid which is centered in the screen, not left justified or right justified. You should continue producing lines until one or more of the following conditions happens: 1. You have used all 9 digits in the output. So you need to keep track of which digits you used. This is may not happen by the way, but check for it any way You have produced the required number of lines. You produced the exact line as the one above it (see the example below). 2. 3. Once one or more of the above conditions stops printing the lines, then you should print a message showing which digits were used in the output. Look at the following example: This is a scenario of your program running. Please enter a positive digit: S Please enter the number of lines in the pyramid: 20 The following is the produced pyramid: 15 1115 3115 2 113 15 3 1121315 41122315 1431221315 4 1221 42315 3 13 2132415 3 12 2331415 3 122331415 The digits 1, 2, 3, 4, and 5 were used

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_2

Step: 3

blur-text-image_3

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

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

List the differences between ITS and PI.

Answered: 1 week ago

Question

=+21.1. Prove ( e-ux2 /2 dx =1-1/2. ,00 12 T = 00

Answered: 1 week ago