Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

java 1-dim array

DJJONES91
DJJONES91 


1. Create a 1-dimensional array with n elements; get the size of the array as user input (validate!), max size should be 10 (declared as class constant). Your program should use modularity. Have methods to: Take input from the user the elements of a 1-dimensional array. Print a 1-dimensional array. Compute the average value/1-dimensional array. Display the difference between each value/1-dimensional array and the average. Display all elements with odd subscripts. Display all elements with even subscripts. Compute the sum of all elements with odd subscripts. Compute the sum of all elements with even subscripts. Generate output similar to the sample output below. SAMPLE RUN: Do you want to start(Y/N): y Enter array size: 7 Now enter 7 values: 56.7 78.9 23.5 111.5 114.7 99.99 88.88 The array elements are: 56.70 78.90 23.50 111.50 114.70 99.99 88.88 The average value = 82.02 Index Value Value - avg =========================== 0 56.70 -25.32 1 78.90 -3.12 2 23.50 -58.52 3 111.50 29.48 4 114.70 32.68 5 99.99 17.97 6 88.88 6.86 The elements with even subscripts are: Index Value ============= 0 56.70 2 23.50 4 114.70 6 88.88 The sum of the elements with even subscripts = 283.78 The elements with odd subscripts are: Index Value ============= 1 78.90 3 111.50 5 99.99 The sum of the elements with odd subscripts = 290.39 Do you want to continue(Y/N): y Enter array size: -4 ERROR! Should be positive and < 10. REENTER: 10 Now enter 10 values: 112 34.5 77.88 55.77 44.7 33.6 117.89 36.78 119.69 56.12 The array elements are: 112.00 34.50 77.88 55.77 44.70 33.60 117.89 36.78 119.69 56.12 The average value = 68.89 Index Value Value - avg =========================== 0 112.00 43.11 1 34.50 -34.39 2 77.88 8.99 3 55.77 -13.12 4 44.70 -24.19 5 33.60 -35.29 6 117.89 49.00 7 36.78 -32.11 8 119.69 50.80 9 56.12 -12.77 The elements with even subscripts are: Index Value ============= 0 112.00 2 77.88 4 44.70 6 117.89 8 119.69 The sum of the elements with even subscripts = 472.16 The elements with odd subscripts are: Index Value ============= 1 34.50 3 55.77 5 33.60 7 36.78 9 56.12 The sum of the elements with odd subscripts = 216.77 Do you want to continue(Y/N): n Attachments
Tags
Clarifications

Answers

1-D Array JAVA Solution

Seeker
Seeker 



...file attached Attachments
OneDimensionalArray.java (2 K) Download Preview
values : ",size); for(int i=0; i<size; i++) array[i] = console.nextDouble(); } public static void sumOdd() { System.out.print("The sum of Elements with odd Subscripts : "); double sum = 0; for(int i=1; i <array.length; i = i+2) { sum +=

Screenshots
Purchase Answer