answersLogoWhite

0


Best Answer

The below method is written in the assumption that, the n numbers are sent as an ArrayList of Integer values.

public void computeSumAndAvg(ArrayList lst){ Iterator itr = lst.iterator();

int sum = 0;

float average = 0;

int count = 0;

while(itr.hasNext(){ Integer val = (Integer) itr.next();

sum = sum + val.intValue();

count++; }

average = sum/count;

System.out.println("Sum is: " + sum) ;

System.out.println("Average is: " + average) ; }

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Java code to average and total a set of numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you do this java code?

You have to specify the task that you wish me to help you with the Java code.


What does the Java compiler translate Java source code to?

The Java compiler translates Java source code to Java byte code.


Write the program in qbasic and add two numbers?

Cls input "enter two no.s ",a,b sum=a+b print "sum = ";sum end


Shogun Total War numbers on cover?

the numbers are the barcode and cd code


What is a simple java code and explain what the code does?

int a;This simple Java statement declares an integer.


In the first step of the Java hybrid compilation process Java program code is converted into an intermediate format called .?

Java byte code.


What kind of file contain java source code?

'.java' files contain java source code. One can access these files on windows by using 'notepad'.


Difference between a java complier and the Java JIT?

A java compiler takes Java source code and turns it into Java bytecode, which can then be run by the java virtual machine.Using JIT means that the java code will be compiled and executed at the time that you run the program, which will slow down the program because it has to compile the code at the same time that it runs.


How can add java code to java server page?

Scriplet.


Java code for tax deduction in database connection?

Java code for tax deduction in database connection?


How is java byte code is different from other low level language?

Java byte-code is the code which generate after the compilation of .java file.And this code is only understand by JVM(java virtual machine ) which understand it and execute it.In other languages this type of functionality is not available.


What is Java byte-code level language?

Java byte-code is the code which generate after the compilation of .java file.And this code is only understand by JVM(java virtual machine ) which understand it and execute it.In other languages this type of functionality is not available.