For my assignment, I have to
"Write a program that reads integers, one per line, and displays their sum. Also, display all the numbers read, each with an annotation giving its percentage contribution to the sum. Use a method that takes the entire array as one argument and returns the sum of the numbers in the array.
I have the array down, as well as the sum, but i cant begin to guess where to start with the part where you have to give the percentage contribution to the sum, and also not so sure what he means by wanting us to put it in a method, like not sure how one passes an array in a method i guess?
any hints? not looking for people to code for me, looking for a point in the right direction...well maybe a strong point xD i hate programming
heres my code
import java.util.Scanner;
public class array
{
public void compute()
{
//nonsense to be entered here
}
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int size, sum = 0;
System.out.println("How many numbers are you going to enter?");
size = keyboard.nextInt();
int[] anArray = new int[size];
System.out.println("Enter " + size + " numbers, one per line");
for (int i = size-1; i >= 0; i--)
{
anArray[i] = keyboard.nextInt();
sum = sum + anArray[i];
}
for (int i = size-1; i >= 0; i--)
{
System.out.println("Numbers entered were:");
System.out.println(anArray[i]);
}
System.out.println("Sum of the numbers is: " + sum);
}
}
thanks