Related questions
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 should 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 may not happen by the way, but check for it any way. 2. You have produced the required number of lines. 3. You produced the exact line as the one above it (see the example below). 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: 5 Please enter the number of lines in the pyramid: 20 The following is the produced pyramid: 5 1 5 1 1 1 5 3 1 1 5 2 1 1 3 1 5 3 1 1 2 1 3 1 5 4 1 1 2 2 3 1 5 1 4 3 1 2 2 1 3 1 5 4 1 2 2 1 4 2 3 1 5 3 1 3 2 1 3 2 4 1 5 3 1 2 2 3 3 1 4 1 5 3 1 2 2 3 3 1 4 1 5 The digits 1, 2, 3, 4, and 5 were used. Your implementation must contain a main class as well as another class called Pyramid. The main program should declare and instantiate a Pyramid class and simply call 3 methods from the Pyramid class. a. A method to read the input b. A method to print the pyramid c. A method to print the digits used. So, the main program should only be 4 statements inside of the main method. All the other code that performs the needed work should be included in the class Pyramid.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images
- Write a Java program to prompt the user to enter a test score, the program asks user to input the score repeatedly until test score which a number in the range of [0,100] is read from users input device. When your program gets a valid score, display A if the given number is greater than 90 or equal, B if it is in [80,90] range, C if it is in [70,80] range, D if it is in [60,70] range, and F for other ranges.arrow_forwardWrite a program that receives an integer from the user and prints Large if that number is greater than or equal to 100, prints average if that number is between 20 and 100, and prints Small if that number is less than or equal to 20. You can get an input from user and convert it to an integer using a = int(input('Please enter an integer:'))arrow_forwardWrite a program to compute the sum of the first N Fibonacci numbers, where N is an integer that is input by the user. Once it computes the sum, the program will prompt the user for a new value of N. The program will exit if the user enters a non-integer number or string (such as "quit") instead of an integer. Language: Java The first four numbers of the Fibonacci sequence are: 0, 1, 1, and 2. Use For loop at least once, can use while loops. Sample Output: Welcome to the Fibonacci AdderTo quit, enter a non-integer number or string How many Fibonacci numbers should be summed? >> 10The sum of the first 10 Fibonacci numbers is: 88 How many Fibonacci numbers should be summed? >> xxx Thank You for Using the Fibonacci Adderarrow_forward
- Write a program that reads an unspecified number of integers, determineshow many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.arrow_forwardI need help with this Java problem as it's explained in the image below: Palindrome (Deque) A palindrome is a string that reads the same backwards and forwards. Use a deque to implement a program that tests whether a line of text is a palindrome. The program reads a line, then outputs whether the input is a palindrome or not. Ex: If the input is: senile felines! the output is: Yes, "senile felines!" is a palindrome. Ex: If the input is: rotostor the output is: No, "rotostor" is not a palindrome. Ignore punctuation and spacing. Assume all alphabetic characters will be lowercase. Special case: A one-character string is a palindrome. Hint: The deque must be a Deque of Characters, but ordinary chars will be automatically converted to Characters when added to the deque. Java Code: import java.util.Scanner; import java.util.LinkedList; import java.util.Deque; public class LabProgram { public static void main(String[] args) { Scanner scnr = new...arrow_forward
- Text book imageComputer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONText book imageComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceText book imageNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Text book imageConcepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningText book imagePrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationText book imageSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY