English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Create an interger array called 'final and initialize with elements {10,20,30,40,50,60,70.80,90,100,.Display the Total, Product and Average of 3rd, 6th and 9th element of the final array.

2007-03-14 18:50:04 · 2 answers · asked by Steven B 1 in Computers & Internet Programming & Design

2 answers

I guess you need to find the total, average and the product of the elements at the indices 3,6 and 9.Though your Q is not clear, here's the probable answer:

class sample
{
public static void main(String args[])
{
int array[]={10,20,30,40,50,60,70,80,90,100};
//You cant create an array with the name 'final' coz its a keyword
int total=0;
long product=0;
double avg=0; //Incase average is a floating-point number

//Calculateing the total
total=array[3]+array[6]+array[9];

//Calculating the product
product=array[3]*array[6]*array[9];

//Calculating the average
avg=total/3;

//Displaying results
System.out.println("The sum of the elements is "+total);
System.out.println("The product of the elements is "+product);
System.out.println("The average of the elements is "+avg);

}}

2007-03-14 19:15:26 · answer #1 · answered by kri91-16 2 · 0 0

You could try to do something like (if I'm reading your issue correctly):

int final[] = {10,20,30,40,50,60,70,80,90,100,0,0,0};

Then figure out the sum, product, and average and place them in final[10], final[11] and final[12].

EDIT: Good catch on using the name final since it is a keyword in Java! I suppose I should be asking, not answering questions...

2007-03-14 18:58:47 · answer #2 · answered by Christina 2 · 0 0

fedest.com, questions and answers