I am trying to assign a number 1-10 to two variables. If the number is greater than max then update max with that number, if the number is less than min, then update min with. All the while updating the total with whatever number gets generated. I thought I had it correct but whenever it generates. Then at the end I must average it. The number isn't random and get's stuck on the same few numbers. Not sure what I have wrong.
package java_programming;
import java.util.Random;
public class Jp{
public static void main(String[] args){
//The Power Operation
double power = Math.pow(5.0,3.0);
//The Square Root Operation
double root = Math.sqrt(12.0);
//The Max Operation
double Maxi = Math.max(23.4, 23.5);
//The Min Operation
double Mini = Math.min(23.4, 23.5);
//The Random Opeartion
double rand = Math.random();
System.out.println("Results");
System.out.println("Math.pow = " + power);
System.out.println("Math.sqrt = " + root);
System.out.println("Math.max = " + Maxi);
System.out.println("Math.min = " + Mini);
System.out.println("Math.random = " + rand);
Jp rs = new Jp();
System.out.println("Min value");
rs.randomStudy();
}
public void randomStudy(){
int total = 0;
int max = -1;
int min = 11;
int iterations = 1000;
Random ran = new Random();
for(int i = 0; i < iterations; i++){
int count = ran.nextInt(10);
min = Math.min(count, min);
max = Math.max(count, max);
total += count;
}
System.out.println("Result of max: " + max);
System.out.println("Result of min: " + min);
System.out.println("Average: " + (1.0 * total / iterations));
}
}