title: how can use random numbers in array?
body: <p>I write code by java but I need convert it to hard copy (that means no enter element by user). I need the program work automatically by using random number. I know the method for random.
  This is my code:</p>
  
  <pre><code>import java.io.*;
  
  class arr
      {
  
          public static void main(String args[])throws IOException
              {
                  BufferedReader br=new BufferedReader(
                      new InputStreamReader(System.in));
                  int ar[]=new int[100];
                  int n,i,j,pos,ch;
                  System.out.print("Enter number of element :-");
                  n=Integer.parseInt(br.readLine());
                  if(n&lt;=99)
                      {
                          for(i=0;i&lt;n;i++)
                              {
                                  System.out.print("Enter any no :-");
                                  ar[i]=Integer.parseInt(br.readLine());
                              }
                          do
                              {
                                  System.out.println("\n1.Ele insert...");
                                  System.out.println("2.Ele delete...");
                                  System.out.println("3.Ele display...");
                                  System.out.println("4.Exit");
                                  System.out.print("Enter your choice :-");
                                  ch=Integer.parseInt(br.readLine());
                                  switch(ch)
                                      {
                                          case 1:
                                              System.out.print("Enter position number :-");
                                              pos=Integer.parseInt(br.readLine());
                                              if(pos&lt;n)
                                                  {
                                                      for(j=n-1;j&gt;=pos-1;j--)
                                                          ar[j+1]=ar[j];
                                                      System.out.print("Enter new inserting element :-");
                                                      ar[j+1]=Integer.parseInt(br.readLine());
                                                      n++;
                                                  }
                                              else
                                                  System.out.println("Sory invalid position number enterde.....");
                                              break;
                                          case 2:
                                              System.out.print("Enter position number :-");
                                              pos=Integer.parseInt(br.readLine());
                                              if(pos&lt;n)
                                                  {
                                                      for(j=pos-1;j&lt;n;j++)
                                                          ar[j]=ar[j+1];
                                                      System.out.println("element deleted......");
                                                      n--;
                                                  }
                                              else
                                                  System.out.println("Sory invalid position number enterde.....");
                                              break;
                                          case 3:
                                              for(i=0;i&lt;n;i++)
                                                  System.out.print(ar[i]+"\t");
                                              System.out.println();
                                              break;
                                          case 4:
                                              System.out.println("Program end.......");
                                              break;
                                          default:
                                              System.out.println("Invalid enter select......");
                                      }
                              }while(ch != 4 );
                      }
                  else
                      System.out.println("Out of range........");
  
              }
      }
  </code></pre>
  
  <p>so my questions are:</p>
  
  <ul>
  <li>how can use random number </li>
  <li>and I want to add more function for find the smallest number and largest number </li>
  </ul>
  
  <p>I have tried using this method for random: </p>
  
  <pre><code>import java.util.Random;
  public class ArrayRandom{
      public static void main(String args[]){ 
          Random r = new Random();
          int arr[] = new int[20];
          for(int i = 0; i &lt; 20; i++){
              //random numbers from 1 to 10:
              arr[i] = r.nextInt(10) + 1;
          }
          for(int i = 0; i &lt; 20; i++){    
              System.out.print(arr[i] + " ");
          }
      }
  } 
  </code></pre>
  
  <p>But it does not work?</p>