Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Creating an array with a text document
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
IntelMaster




PostPosted: Tue May 25, 2010 5:50 pm   Post subject: Creating an array with a text document

Hi,

I want to take the numbers from a text document and make an array out of it, but for some reason my program is not working. After gathering the arrays I want to calculate the median for the numbers. Here is my program so far:
Java:

                String amounta=jTextField8.getText();
                int amount=Integer.parseInt(amounta);
                int sum=0;
                try {
                        FileInputStream in = new FileInputStream("numbers.txt");
                        BufferedReader br = new BufferedReader(new InputStreamReader(in));
                       
                        int numbers[] = new int[amount];
                        for (int count = 0; count==amount; count++){
                                numbers[count] = Integer.parseInt(br.readLine());
                                sum=sum+numbers[count];
                                System.out.println(sum/amount );
                        }
                        in.close();       
                }catch (Exception e)
                {
                       
                }
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Tue May 25, 2010 6:04 pm   Post subject: RE:Creating an array with a text document

Make sure your file is really 'numbers.txt' and not 'numbers.txt.txt'. Happens a lot (to me). Damn you Windows, I'll type my own extensions!

Other than that, I can't think of what's wrong (due in no small part to my inability to read Java without my head exploding).
DemonWasp




PostPosted: Tue May 25, 2010 6:49 pm   Post subject: RE:Creating an array with a text document

@Insectoid: you can force Windows Explorer to always show extensions. This is one of the first things I do whenever I set up Windows, because foobar.bmp.jpeg has always been a stupid, irritating problem.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: