7. (6 marks) Write a program to ask user to enter an integer that represents the number of elements, then generate an Ar
-
- Site Admin
- Posts: 899558
- Joined: Mon Aug 02, 2021 8:13 am
7. (6 marks) Write a program to ask user to enter an integer that represents the number of elements, then generate an Ar
REQUIREMENTS
Example of the program output:
Example 1:
Enter the number of elements: 5
Index Element Triple
4 126 378
3 97 291
2 53 159
1 133 399
0 81 243
Example 2:
Enter the number of elements: 12
Index Element Triple
11 198 594
10 185 555
9 158 474
8 75 225
7 168 504
6 62 186
5 58 174
7. (6 marks) Write a program to ask user to enter an integer that represents the number of elements, then generate an ArrayList containing elements which are all random integers in range [50, 199] (50 and 199 are both included), and finally display index, element value and triple element value in the reverse index order. REQUIREMENTS • The user input is always correct (input verification is not required). Your code must use ArrayList. Your program must use only printf(...) statements to adjust the alignment of your output. Your code must display the index in reverse order. Your output must be displayed with the same alignment as the example (the text in bold indicates the user input). Example of the program output: Example 1: Enter the number of elements: 5 Index Element Triple 4 126 378 3 97 291 2 53 159 1 133 399 0 81 243 Example 2: Enter the number of elements: 12 Index Element Triple 11 198 594 10 185 555 158 474 75 225 168 504 62 186 58 174 HO 9896 in 7 5