Jump to content

Input/Output

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Guest_scarfacemontana_*

Guest_scarfacemontana_*
  • Guests
Hello

I have written a program that stores 1000 random numbers in an array, and finds the average. The question is, how do I actually test it? When I try to run it, all that comes up is the class name. Here is the code:

 import java.util.*;

import java.io.*;



public class Random

{

   public static void main(String[] args)

   {

      double [] random = new double[1000];

      

      for( int i = 0; i < random.length; i++)

      {

          random[i] = Math.random();

         

      double sum = 0;

      for (int j = 0; j < random.length; j++)

         sum += random[i];

      

      double average = sum/random.length;

      

      }

   }

}

         

       

Can someone help me with how I would incorporate input/output?

Thanks a lot

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
To output it, you can just add a

System.out.println(random[j]);

in the for loop