Q:

Printing the max number from MathRandom generated numbers

My task is to print 1,000,000 random numbers between 0 and 1 with the use of loops.
I've chosen to use the function Math.random to do this and a for loop to create 1,000,000. 
Now I need to print the max value of the numbers...but how? Is it possible to do it within putting them into an array?
Here's my code so far:
public class GenerateRandomNumbers    
{    
public static void main(String[]args)
    {
        for(int i=0; i < 1000000; i++){
        System.out.println(Math.random());
        }       
    }   
}

A:

You simply need to keep track of the current maximum, and update it accordingly:
public static void main(String[]args) {
    double max = 0.0d;
    for(int i=0; i < 1000000; i++){
        double x = Math.random();
        max = Math.max(max,x);
        System.out.println(x);
    }
    System.out.println("The maximum is "+max);
}

The code works as follows: from the specifications of Math.random, we known that the lowest value is 0.0, so we first set max to 0.0d.
Next we iterate over the 1000000 samples. Before printing the value, we first store it in a double x. Next we update the maximum: max stored the maximum thus far, by calculating the maximum of max and x, we include x as well.
Finally after the for loop, we know for sure that max contains the maximum value encountered, and we can print it (or do other things with it).

