# Array Operations

• February 9th, 2012, 08:10 PM
knoxb
Array Operations
Hi,

I can't seem to figure this out. I'm trying to create a program that takes user input to create an array. A loop will then print out possible operations to perform that the user will select. The operations will be count, sum, average, min, max, and standard deviation.

Any help will be very appreciated.

Thank you.
• February 9th, 2012, 11:30 PM
Mr.777
Re: Array Operations
What did you try? Paste your code here you have done until now and we can help you. We don't do homework.
• February 10th, 2012, 12:07 AM
knoxb
Re: Array Operations
Here is what I have so far. Most of this is from a similar program I found online. I'm just trying to get it working so I can understand it. I'm not sure where to go from here.

package arrayoperations;

import java.util.Scanner;

public class ArrayOperations {

double count;
double sum;
double average;
double min;
double max;
double sd;

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("How many numbers do you want to enter?");
int num = input.nextInt();

int array[] = new int[num];

System.out.println("Enter the " + num + " numbers now.");

for (int i = 0 ; i < array.length; i++ ) {
array[i] = input.nextInt();
}

System.out.println("These are the numbers you have entered.");
printArray(array);
System.out.println("\nWhich action would you like to perform? \n1 for count, 2 for sum, 3 for average, 4 for min, 5 for max, or 6 for standard deviation: ");

}

public static void printArray(int arr[]){

int n = arr.length;

for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");

}

}

}
• February 10th, 2012, 12:21 AM
Mr.777
Re: Array Operations
Do you know what this program does? And what else you want it to do?
Also, close your code in code tags, for the ease of understanding.
• February 10th, 2012, 01:51 AM
knoxb
Re: Array Operations
Right now it is just taking user input for an array and printing the array out. I need a loop to print out possible operations to perform on the array. Count, sum, average, min, max, and standard deviation. I am not sure how to start that part. Any tips on how to do that would be awesome.
• February 10th, 2012, 02:13 AM
Mr.777
Re: Array Operations
Right. So, take a copy and pencil and start doing the counting of array numbers. Write down the points how are you doing this and implement them as Java language. Same as all other operations.
Hope you will be able to solve this. If you get stuck in your code, ask here for more help.
• February 10th, 2012, 05:01 PM
knoxb
Re: Array Operations
Any tips on how to code the operations for the array?

Quote:

package arrayoperations;

import java.util.Scanner;

public class ArrayOperations {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.println("How many numbers do you want to enter?");
int num = input.nextInt();

int array[] = new int[num];

System.out.println("Enter the " + num + " numbers now.");

for (int i = 0 ; i < array.length; i++ ) {
array[i] = input.nextInt();

}

System.out.println("These are the numbers you have entered.");
printArray(array);

}

public static void printArray(int arr[]){

int n = arr.length;

for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");

}
double option;
System.out.println("\nWhich action would you like to perform? \n1 for count, 2 for sum, 3 for average, 4 for min, 5 for max, or 6 for standard deviation: ");
for(int i = 0; i < n; i++){
if(option == 1 ){
System.out.println("count");
} else if (option == 2){
System.out.println("sum");
} else if (option == 3){
System.out.println("average");
} else if (option == 4){
System.out.println("min");
} else if (option == 5){
System.out.println("max");
} else if (option == 6){
System.out.println("standard deviation");
} else {
System.out.println(option);

}

}
}
}
• February 10th, 2012, 05:29 PM
pbrockway2
Re: Array Operations