# How to divide elements in two different arrays

• February 11th, 2011, 02:42 PM
BuhRock
How to divide elements in two different arrays
I am using an array to store 5 test scores. Then I have another array for the total possible score the test could have. I just need to find out what percent the grade is out of the total possible score.

Code :

public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int[] outOf = new int[5];
int[] percents = new int[5];

int total = 0;
int average;
int percent;

outOf[0] = 210;
outOf[1] = 100;
outOf[2] = 150;
outOf[3] = 200;
outOf[4] = 50;

{

}

average = total / 5;

System.out.println("The total is " + total + "\nThe"
+ " average is " + average);
}

{

}
}

• February 11th, 2011, 02:58 PM
copeg
Re: How to divide elements in two different arrays
Quote:

I just need to find out what percent the grade is out of the total possible score.
Divide one by the other and multiply by 100.

Just a recommendation, but using an Object Oriented approach you could get the results fairly easily. For example, if you created a class called Test that contains the score and total possible score - the data is inherently packaged together in a way than can be easily understood and manipulated.
• February 11th, 2011, 03:22 PM
BuhRock
Re: How to divide elements in two different arrays
Yeah I know thats the formula on how to get the percent, but I dont know how to implement that. I have tried:
Code :

percents[0] = (grade[0] / outOf[0]) * 100;

System.out.println(percents[0]);

I am getting 0 as an output though. Why is this?
• February 11th, 2011, 03:58 PM
newbie
Re: How to divide elements in two different arrays