Write a program that does the following: 1. Prompt the user for number of rows and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program that does the following: 1. Prompt the user for number of rows and columns of an array; acceptable numbers are between 2 and 20. If the number entered is outside of this range, inform the user and prompt again. 2. Create a two-dimensional array of integers of the size entered above using the same number of rows as columns 3. Populate the array with randomly generated integer numbers between 0 and 99, including both numbers. 4. Display the array contents, one row per line. 5. Display the sum of the two diagonals in the array, as follows: 1 2 3 1 2 3 45 6 7 8 9 7 8 9 Diagonal #1 1+5+9=9+5+1-15 Diagonal #2=7+5+3=3+5+7=15 6. The program must implement at least the following methods: a displayArray: displays array contents, one row per line as shown below b sumOfDiagonals: calculates and displays the sum of elements placed diagonally in the array Both methods must use: parameters: two-dimensional integer array return type: none Sample Program Run #1 Enter number of rows and columns (2-20): 1 Invalid entry please try again Enter number of rows and columns (2-20): 2 Array contents: 57 69 99 98 Diagonal 1 sum is: 155 Diagonal 2 sum is: 168 Sample Program Run #2 Enter number of rows and columns (2-20): 21 Invalid entry please try again Enter number of rows and columns (2-20): 10 Array contents: 35 51 38 2 79 88 97 8 68 47 21 72 16 26 57 83 16 58 55 93 43 71 38 23 45 82 96 14 6 82 16 20 33 1 51 86 62 43 91 9 57 93 51 44 8 25 98 11 47 52 91 95 40 54 1651 48 87 98 79 99 93 71 87 88 31 34 83 58 24 78 94 64 69 80 96 6 27 46 60 55 72 7 35 67 40 35 15 63 14 23 59 88 12 81 36 95 91 37 Diagonal 1 sum is: 327 Diagonal 2 sum is: 498 Notes: 1. You may only use material covered in this course so far 2. Programs with syntax errors will not be accepted Write a program that does the following: 1. Prompt the user for number of rows and columns of an array; acceptable numbers are between 2 and 20. If the number entered is outside of this range, inform the user and prompt again. 2. Create a two-dimensional array of integers of the size entered above using the same number of rows as columns 3. Populate the array with randomly generated integer numbers between 0 and 99, including both numbers. 4. Display the array contents, one row per line. 5. Display the sum of the two diagonals in the array, as follows: 1 2 3 1 2 3 45 6 7 8 9 7 8 9 Diagonal #1 1+5+9=9+5+1-15 Diagonal #2=7+5+3=3+5+7=15 6. The program must implement at least the following methods: a displayArray: displays array contents, one row per line as shown below b sumOfDiagonals: calculates and displays the sum of elements placed diagonally in the array Both methods must use: parameters: two-dimensional integer array return type: none Sample Program Run #1 Enter number of rows and columns (2-20): 1 Invalid entry please try again Enter number of rows and columns (2-20): 2 Array contents: 57 69 99 98 Diagonal 1 sum is: 155 Diagonal 2 sum is: 168 Sample Program Run #2 Enter number of rows and columns (2-20): 21 Invalid entry please try again Enter number of rows and columns (2-20): 10 Array contents: 35 51 38 2 79 88 97 8 68 47 21 72 16 26 57 83 16 58 55 93 43 71 38 23 45 82 96 14 6 82 16 20 33 1 51 86 62 43 91 9 57 93 51 44 8 25 98 11 47 52 91 95 40 54 1651 48 87 98 79 99 93 71 87 88 31 34 83 58 24 78 94 64 69 80 96 6 27 46 60 55 72 7 35 67 40 35 15 63 14 23 59 88 12 81 36 95 91 37 Diagonal 1 sum is: 327 Diagonal 2 sum is: 498 Notes: 1. You may only use material covered in this course so far 2. Programs with syntax errors will not be accepted
Expert Answer:
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Network Infrastructure Architecture For the scenario below, represent in an Infrastructure Architecture diagram all distinct network architecture components and how they integrate with each other....
-
Examine the following program: class Exercise1 { public static void main (String[] args ) { int[] val = {0, 1, 2, 3}; sum = System.out.println( "Sum of all numbers = " + sum ); } } Complete the...
-
Microkernel operating systems aim to address perceived modularity and reliability issues in traditional "monolithic" operating systems. (i) Describe the typical architecture of a microkernel...
-
Please watch the video link and answer the following questions. https://youtu.be/VtvjbmoDx-I On January 22,1984, Apple produced one of the most famous Super Bowl ads of all time. Directed by Ridley...
-
Describe how you would prepare the following compounds: (a) Mg(OH)2 , (b) AgI, (c) Ba3(PO4)2.
-
Consider a liquid-fueled rocket engine burning liquid hydrogen as the fuel and liquid oxygen as the oxidizer. The hydrogen and oxygen are pumped into the combustion chamber at rates of \(11...
-
\(\frac{15^{14}}{15^{11}}\) Simplify the expression.
-
Revenue Recognition on Book Sales with High Returns) Uddin Publishing Co. publishes college textbooks that are sold to bookstores on the following terms. Each title has a fixed wholesale price, terms...
-
PCW Co is a listed company that operates in the automobile industry. Due to an increase in local demand for the company's products, PCW Co decides to invest in a new machinery. Such an investment...
-
A probability plot of 66 yr of peak discharges for the Kentucky River near Salvisa, Kentucky, is shown in Fig. P3-19 (a) What probability distribution is being used? (b) What are the mean and...
-
1. P=C+O+M C +I+M. Explain each term and where it is derived from? What is a direct cost and what terms in this expression are direct costs? What is an indirect cost and what terms in this expression...
-
discuss the impact of negative interest rates on deposit behavior, exploring the economic rationale behind this unconventional monetary policy tool and its effects on consumer saving habits, bank...
-
1. Locate a deed from Texas and then answer the following questions: What language does the deed have concerning consideration? Explain what the covenant of seizin is. Does the deed contain a...
-
Provide a brief summary of the case. 2. Do you think that this case contains the five elements to prove negligence? Explain using legal reasoning and facts. 3. How would you rule in this case?...
-
A body temperature of 97.0 F is slightly lower than the "normal" value but is still considered acceptable as an individual's temperature can have variable norms. What would this temperature equate to...
-
Explain how to become a stockbroker in Canada and France and how to achieve your Chartered Financial Analyst (CFA) certification in both countries .The investigation should be somewhat detailed in...
-
Explain the lifecycle of a thread from creation to termination. What are the different thread states, and how does the operating system manage transitions between them?
-
Borrowing costs should be recognised as an expense and charged to the profit and loss account of the period in which they are incurred : A. If the borrowing costs relate to qualifying asset B. If the...
-
Listing 28.10, ConnectedCircles.java, allows the user to create circles and determine whether they are connected. Rewrite the program for rectangles. The program lets the user create a rectangle by...
-
Modify Programming Exercise 22.21 to display the intermediate results of the search. Figure 30.32 gives a snapshot of an animation in progress with number 2 placed in the cell in Figure 30.32a,...
-
Write a program that reads the integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0. Hereis a sample run of the program: If a number occurs more than one time,...
-
Question: The stock market crash of 1929 and the Great Depression that followed were caused in part because so many investors blindly put their money into stocks they knew nothing about. During the...
-
Question: Bill and Diane are hiking in the woods. Diane walks down a hill to fetch fresh water. Bill meets a stranger, who introduces herself as Katrina. Bill sells a kilo of cocaine to Katrina, who...
-
Strategy: Look at the ethics checklist. Citizens of China are stakeholders of American companies. Although it is legal to buy fabric from a company that is polluting overseas, this is surely...
Study smarter with the SolutionInn App