import java.util.Random;
class justrandom{
public static void main(String[] args) {
Random dice = new Random();
double[] allgrades = new double[20];
double sum = 0;
double average = 0;
double low = 100;
double high = 0;
for(int counter=1; counter< 20;counter++){//loop that generates rand number 20 times
int number = 60+dice.nextInt(40);
allgrades[counter] = number;//numbers are now held in array
}
for (int hilow = 1; hilow < 20; hilow++) { //2nd loop for hilow values
double sumhelper = allgrades[hilow];
sum += sumhelper;
if (allgrades[hilow] > high) { //finds high
high = allgrades[hilow];
}
if (allgrades [hilow] < low) { //finds low
low = allgrades[hilow];
}
}
average = sum/20.0;
System.out.println("Average is " + average + " High is " + high + " Low is " + low); //final output
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.