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.
-
George Large (SSN 000-11-1111) and his wife Marge Large (SSN 000-22-2222) live at 2000 Lakeview Drive, Cleveland, OH 49001 and want you to prepare their 2015 income tax return based on the...
-
Minaret, Inc., issued 10,000 shares of \(\$ 50\) par value preferred stock at \(\$ 68\) per share and 12,000 shares of no-par value common stock at \(\$ 15\) per share. The common stock has no stated...
-
Diageo is a United Kingdom (UK) consumer products firm, best known in the United States for the following brand names: Smirnoff, Johnnie Walker, J&B, Gordons, Seagrams, and Guinness. Diageos 2007...
-
210) Keturns 220) Interest Rates 240) Volatility 200) Refresh 203) Single Ranking 201) Table 204 Historical Ranking 205) Multiple Ranking 202) Export World Currency Ranker Base USD Values as of...
-
Access NSW Fair Trading's website at Licensing Requirements and summarise the main requirements for the following classes of licence and certificate for personal development of certificated and...
-
Describe the relationship between the main processor and coprocessor in a system with which you are familiar or one that you discover through Web research.
-
Discuss the differences between quantitative and qualitative in terms of materiality.
-
What is participative auditing? How might it help improve auditor-auditee relationships? Do you see any dangers?
-
Should the auditors comment on the satisfactory review and testing of the accounting and internal control systems in the auditors report?
-
Outline three approaches to conflict management when it occurs within an organization.
-
Compute for the cost of goods sold 2) How much is the operating expenses budget 3)If the sales budget is based on a target gross margin of 62% sales, how much is the operating income budget? 4)From...
-
g(x) = x 5 5x 6 a. Show that g(x) = 0 has a root, , between x = 1 and x = 2. b. Show that the equation g(x) = 0 can be written as x = (px + q) 1/r , where p, q and r are integers to be found. 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,...
-
Determine the quick ratio for the commercial construction company. What insight does this give you into the companys financial operations?
-
Determine the current ratio for the commercial construction company . What insight does this give you into the companys financial operations?
-
Determine the current liabilities to net worth ratio for the commercial construction company. What insight does this give you into the companys financial operations?
Study smarter with the SolutionInn App