Thursday 23 July 2015

Generate Random 10,000 numbers and store as 100*100 array in csv file.



try
        {
        Random r = new Random();
        //System.out.println("Numbers are");
      File file = new File("D:/p2.csv");
     
      FileWriter writer = new FileWriter(file);
    
      System.out.println("start");
        for(int i=1;i<=100;i++)
        {
            for(int j=1;j<=100;j++)
            {
                int value;
                value=r.nextInt(10000);
               writer.append(Integer.toString(value)+" ");                
            }
            writer.append('\n');
            writer.flush();
        }
        writer.close();
        System.out.println("end");
        }
        catch(Exception e)
        {
            System.out.println(e);
        }
    }                                        
      

No comments:

Post a Comment