hey guys so i am having a problem in my assinghmnet . i am making a text file and it has to import to java and make a table from the text file .
so there is what the txt file looks.
3 // this should be the rows 1,2,3,
3 // this should be the col 1,2,3,
5
1 2
3
2 2
3 2
0 0// this should exit it//
so , how do i make write a code that would read this text file and make it like a table?
thank you in advance

Think about it and come up with something yourself. We need to have proof of your efforts in order to help you.

Show us what you've done so far and we'll help you from there...

This is what i have done till now.

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;



public class gol {

public static void main(String [] args) throws FileNotFoundException {


    String fileName = args[0];

    Scanner txtfile= new Scanner(new File(fileName));
    System.out.println("Input file: "+fileName+"\n");





         }
     }

Okay, that's good... now to read from that file line-by-line, you can do something like:

String line = "";
while (txtFile.hasNextLine()) {
    line = txtFile.nextLine()
}

But, now think of how you'd read the data to facilitate your problem. Maybe after reading a particular line, you would like to read the different "tokens" in that line. Guess what, that Scanner class you're using has something for reading different tokens in the same line too. Scanner API

Also, just to be clear, the 3rd line of the text file is what? Is it the item in the (0,0) position of the table?

i am making a program game of life and 5 is number of generations. others are the coordinates and 00 is an exit.

If you want table like structure,You can create CSV(comma seperated value file) file and open it with Microsoft Excel,it will look like tabular form.

you can read line by splitting it with space and accordingly put it into new file.

@java123456
I am unable to understand the game program.
Hence Please provide the complete information (clearly and more elaborately if you feel so).
Please dont give the information in pieces. Also dont wait until other forum members ask you the missing information in your problem.

How is generation in your problem related to line numbers & column numbers.

So you have given 4 types of inputs
1)line numbers , 2)column numbers, 3)generation 4)co-ordinates

You have not informed here how the game is played.

What are the game rules.

how are these inputs related?

The value at at line 5 is 3 , What does this mean ?(is it (3,0)?)
You said every thing after line 3 are co-ordinates ? then how come only one value at
line 5 instead of two.

Once again can you provide the complete and full information of your game.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.