1. Create an array named arr1 with 20 random numbers between 1 and 10(inclusively). Then produce a new array arr2 based on arr1 as follows: arr2 has the same length as arr1. In arr2, each element is the sum of the corresponding element in arr1 and the previous element of arr1, except the first number in arr2 equals the first number in arr1. For example, 25 19 3 7 6... If arr1 has the elements: Then arr2 will be: Please display the two arrays. 2 7 6 10 12 10 13...

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
Related questions
Question
100%
1. Create an array named arr1 with 20 random numbers between 1 and 10(inclusively). Then
produce a new array arr2 based on arr1 as follows: arr2 has the same length as arr1. In arr2, each
element is the sum of the corresponding element in arr1 and the previous element of arr1, except
the first number in arr2 equals the first number in arr1. For example,
If arr1 has the elements:
Then arr2 will be:
2 5 19 3 7 6...
2 7 6 10 12 10 13...
Please display the two arrays.
Transcribed Image Text:1. Create an array named arr1 with 20 random numbers between 1 and 10(inclusively). Then produce a new array arr2 based on arr1 as follows: arr2 has the same length as arr1. In arr2, each element is the sum of the corresponding element in arr1 and the previous element of arr1, except the first number in arr2 equals the first number in arr1. For example, If arr1 has the elements: Then arr2 will be: 2 5 19 3 7 6... 2 7 6 10 12 10 13... Please display the two arrays.
Expert Solution
Step 1

The answer is (the output differ because we use random number)

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage