Question

In: Computer Science

Project: Given an array numbers. We define a running sum of an array as runningSum[i] =...

Project:

Given an array numbers. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).

Return the running sum of numbers.

Example:

Input: nums = [1,2,3,4]

Output: [1,3,6,10]

Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].

You need to do: Create a class called RunningSumArray to perform the main method. Create a class called ArrayOperationto hold the actions for array. In this project, you will need 4methods:

1. Public static Int[] getArray() --- inside ArrayOperationclass, using loop generate a n items array.
2. Public static void runnungSum(int[] inputArray) --- inside ArrayOperation class, process the array to calculate the sums. An array is an object, passing an array to a method is passing by reference.
3. Public static void printArray(int[] result) --- inside ArrayOperation class, print the array in a [1, 2, 3, 4, 5] form.
4. Public static void main(string[] args) --- Prompt user to input a whole number between 5 and 10, using the user input number to generate the array, perform calculation, and print out the array before and after calculation,

Solutions

Expert Solution

Code

ArrayOperation class


import java.util.Scanner;

public class ArrayOperation {
public static int[] getArray()
{
int n;
int inputArray[];
Scanner scnr=new Scanner(System.in);
System.out.print("Enter size of array between 5 to 10: ");
n=scnr.nextInt();
inputArray=new int[n];
for(int i=0;i<n;i++)
{
System.out.print("Enter "+(i+1)+" element: ");
inputArray[i]=scnr.nextInt();
}
return inputArray;
}
  
public static void runningSum(int[] inputArray)
{
int runningSumArray[]=new int[inputArray.length];
for(int i=0;i<inputArray.length;i++)
{
int sum=0;
for(int j=0;j<=i;j++)
sum+=inputArray[j];
runningSumArray[i]=sum;
}
System.out.print("After Running sum Array is: ");
ArrayOperation.printArray(runningSumArray);
}
public static void printArray(int[] result)
{
int i;
System.out.print("[");
for(i=0;i<result.length-1;i++)
System.out.print(result[i]+", ");
System.out.println(result[i]+"]");
}
}

RuunningSumArray class


public class RunningSumArray {
public static void main(String[] args) {
int inputArray[]=ArrayOperation.getArray();
System.out.print("Origingal array is: ");
ArrayOperation.printArray(inputArray);
ArrayOperation.runningSum(inputArray);
}
  
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

Given an array A of n distinct numbers, we say that a pair of numbers i,...
Given an array A of n distinct numbers, we say that a pair of numbers i, j ∈ {0, . . . , n − 1} form an inversion of A if i < j and A[i] > A[j]. Let inv(A) = {(i, j) | i < j and A[i] > A[j]}. Define the Inversion problem as follows: • Input: an array A consisting of distinct numbers. • Output: the number of inversions of A, i.e. |inv(A)|. Answer the following:...
Given an array of n numbers, not necessarily in sorted order, we wish to find: (i)...
Given an array of n numbers, not necessarily in sorted order, we wish to find: (i) the range (max - min) and (ii) the interquartile range (IQR) of the numbers. IQR is defined as the difference between the number at the 25% percentile and the number at the 75% percentile. What is the exact number of comparisons needed for computing the range and why? Using any algorithm from the chapters of the textbook covered so far as a subroutine, give...
Given an array A of n distinct real numbers, we say that a pair of numbers...
Given an array A of n distinct real numbers, we say that a pair of numbers i, j ∈ {0, . . . , n−1} form an inversion of A if i < j and A[i] > A[j]. Let inv(A) = {(i, j) | i < j and A[i] > A[j]}. Answer the following: (a) How small can the number of inversions be? Give an example of an array of length n with the smallest possible number of inversions. (b)...
. As input you are given two arrays: an array of numbers ? and an array...
. As input you are given two arrays: an array of numbers ? and an array ? of queries where each query is a target number. The array ? is unsorted and may contain duplicates. Your goal is, for each query ? in the array ?, count the number of pairs in the array ? that sums up to ?; that is, the number of distinct pairs of indices [?, ?], with ? < ?, such that ?[?] + ?[?]...
Write a python program to sum the prime numbers existing in an array . For instance...
Write a python program to sum the prime numbers existing in an array . For instance , if A = [4, 7, 12, 3, 9] the output should be 10
Given a 2D array a, sum up ALL the edges of the array. Ex. int a[...
Given a 2D array a, sum up ALL the edges of the array. Ex. int a[ ][ ] = { {1, 2, 3, 4},                        {5, 6, 7, 8},                        {9, 10, 11, 12} }; OUTPUT: Sum of the edges = 65
Write a program in Easy68K: a) Define an array of numbers in the memory.
Write a program in Easy68K: a) Define an array of numbers in the memory. b) Read two numbers from keyboard. The first number is the size of the array and the second number is what index of the array you want to access. The index you entered can be larger than the array. c) Display the element indexed by (index % size) in the array. 
Given an array of numbers, find the index of the smallest array element (the pivot), for...
Given an array of numbers, find the index of the smallest array element (the pivot), for which the sums of all elements to the left and to the right are equal. The array may not be reordered. Example arr=[1,2,3,4,6] the sum of the first three elements, 1+2+3=6. The value of the last element is 6. Using zero based indexing, arr[3]=4 is the pivot between the two subarrays. The index of the pivot is 3. Function Description Complete the function balancedSum...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array and remove the duplicates in-place such that each element appears only once in the input array and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Find the time complexity of your removeDuplicates() method in Big-O notation and write that in a comment line on the top...
Write a program in Easy68K: a) Define an array of numbers in the memory. b) Read...
Write a program in Easy68K: a) Define an array of numbers in the memory. b) Read two numbers from keyboard. The first number is the size of the array and the second number is what index of the array you want to access. The index you entered can be larger than the array. c) Display the element indexed by (index % size) in the array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT