Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: I NEED HELP

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I NEED HELP

    Read the file and populate a two-dimension array
    To start, you have to read from the text file called “project1.txt”. The text file looks like this:
    5,5
    1,1,3,5,7
    ...
    The first line of the file is the size of the 2 dimensional array. The next sets of lines are the numbers themselves. For the data file, you can assume that the data is all correct (i.e. correct dimension and all numbers).
    The array itself will be an instance variable for the class. Populate the array with a method called readFile() that takes the array and file name as its parameters. It also makes use of TextFileInput.java that you were provided in lab. NOTE: It will be very helpful to declare two instance variables to indicate the size of the row and column. It will be clear later on.
    Write a method called findMin() that will find and display to a JOptionPane, all the smallest values in each row of the array.
    Last edited by Cbasha7; October 11th, 2012 at 08:59 PM.

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: I NEED HELP

    What code do you have so far? What do you need help with specifically? Are you getting any errors or exceptions? If so, please post them. The more details you provide the better.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    Cbasha7 (October 11th, 2012)

  4. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I NEED HELP

    This is what I have so far and all it does is the read the file.

    ]import java.io.*;
    class Project1{ 
     
    public int row;
    public int col;
     
     
     public static void main(String args[])
      {
     
     try{
     
      FileInputStream fstream = new FileInputStream("src/project1.txt");
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;
      while ((strLine = br.readLine()) != null)   {
      System.out.println (strLine);
      }
     
      in.close();
        }catch (Exception e){
      System.err.println("Error" );
      }
      }
     
     
     
    }
    I need help mostly with declaring two instance variables to indicate the size of the row and column in the text file.
    Last edited by helloworld922; October 11th, 2012 at 09:38 PM. Reason: please use code tags

  5. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: I NEED HELP

    Oracle has a tutorial for Declaring Member Variables

Tags for this Thread