Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that does the following: 1. Prompt the user for number of rows and columns of an array; acceptable numbers are between

   

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

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

Introduction to Java Programming, Comprehensive Version

Authors: Y. Daniel Liang

10th Edition

133761312, 978-0133761313

More Books

Students also viewed these Programming questions

Question

Describe ways to overcome resistance to change. LO.1

Answered: 1 week ago