Skip to content

Instantly share code, notes, and snippets.

@lb7n
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lb7n/2fbc5298febc79e9aa7c to your computer and use it in GitHub Desktop.
Save lb7n/2fbc5298febc79e9aa7c to your computer and use it in GitHub Desktop.
program that calculates the average of 2 random numbers looping it 1000 times and saving to an array list
package loop;
import java.util.ArrayList;
public class Mainclass {
public static void main(String[] args)
{
ArrayList<Integer> Random = new ArrayList<Integer>();
int upperBound = 1000;
int lowerBound = 1;
for(int i=0; i<upperBound; i++){
int randomNumber = (int)(Math.random() * ((upperBound - lowerBound) + 1) + lowerBound);
int randomNumber2 = (int)(Math.random()* ((upperBound - lowerBound) + 1)+ lowerBound);
int x = (randomNumber + randomNumber2)/2;
Random.add(x);
System.out.println(x);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment