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
-
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...
-
Someone spilled concentrated sulfuric acid on the floor of a chemistry laboratory. To neutralize the acid, would it be preferable to pour concentrated sodium hydroxide solution or spray solid sodium...
-
Describe sustainability and sustainable business practices.
-
Choose a sport and describe at least three different statistics commonly tracked by participants in or spectators of the sport. In each case, briefly describe the importance of the statistic to the...
-
Allegheny Mountain Power and Light is an electric utility company with a large fleet of vehicles including automobiles, light trucks, and construction equipment. The company is evaluating four...
-
Tesla Inc. (US electric vehicle manufacturer) intends to receive 375,000 in 3 months and is concerned that the exchange rate expectations over the next three months would affect their receivables...
-
Leonette decided that Meaghan was smart to get her business started by buying on the installment plan. That way she would have an operating expense and keep her ready cash as operating capital....
-
Mrs. Green is a client of your agency. She has been diagnosed with multi-infarct (vascular) dementia. She has been assessed to be in the first stage and is only mildly forgetful the majority of the...
-
ABC Video sells VCRs and television sets. On July 1 of the current year, ABC sells a color T.V. to D, one of its sales clerks, for $400. The T.V. normally retails to customers for $600 and ABC's...
-
What value does the following program output? #include int main() { } int i; float x=1; for (i=3;i <6;i=1+2) x = (x + 5/x)/3; printf("%f ", x); return 0;
-
Find a healthcare issue (past or present) that is central to an ethical problem. A thorough discussion of the issue (what lead up to it and what is the current status) What is the (potential) impact...
-
You bought on margin 200 shares of AMC Entertainment stock at $4 per share. The initial margin requirement is 60%. The maintenance margin requirement is 30%. Suppose the stock value increases to $15...
-
Explain the importance of regulating blood glucose levels and possible conditions associated with improper regulation.
-
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...
-
Use the magnitudes (Richter scale) of the earthquakes listed in Data Set 16 in Appendix B. In 1989, the San Francisco Bay Area was struck with an earthquake that measured 7.0 on the Richter scale....
-
Which do you think has less variation: the IQ scores of students in your statistics class or the IQ scores of a simple random sample taken from the general population? Why?
-
Based on data from Data Set 17 in Appendix B, the words spoken in a day by women have a mean of 16,215 words and a standard deviation of 7301 words. Consider the women with an unusual word count in a...
Study smarter with the SolutionInn App