Adding up all values generated from a for-loop
Here's the code I have:
It's part of a much bigger program, but the details don't matter. Essentially what I need is to add up all of the values that will be generated by this code and store them in a variable.
public class Assignments
public static void main (String args)
Random gradeGenerator = new Random();
int finalAssignments = 0;
int grade = 0;
for (int i=1; i<=6; i++)
grade = gradeGenerator.nextInt(100) + 1;
System.out.println("The grade for assignment " + i + " is " + grade);
For instance, if all my values happen to be 1, then the final variable would be 15 because it added up all of the 1's.
Thanks for any help! I've only been in a java class for a few weeks now, and I have a strong feeling that this is a really stupid question... thanks for dealing with the beginner!