input-output

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 733 Views - Last Post: 27 March 2011 - 06:46 PM Rate Topic: -----

#16 javabeginner18  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 16
  • Joined: 04-March 11

Re: input-output

Posted 27 March 2011 - 03:42 PM

View PostManbearpig101, on 27 March 2011 - 03:33 PM, said:

View Postjavabeginner18, on 27 March 2011 - 03:32 PM, said:

View Postpbl, on 27 March 2011 - 03:30 PM, said:

View Postjavabeginner18, on 27 March 2011 - 05:15 PM, said:

sorry sir my english is bad. just i wanna this: this txt copy an array :)

An array of what ? String[][] or char[][]

If String[][] based on letters or word ?

i am really sorry i wanna use char . because i use "##"


Look at the code I put above >.<

this code is wrong i think. because prgram give an error
Was This Post Helpful? -1
  • +
  • -

#17 Manbearpig101  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 62
  • Joined: 17-June 10

Re: input-output

Posted 27 March 2011 - 03:44 PM

I was giving an example, not a copy + paste code.
But what error did you exactly get?
Was This Post Helpful? 2
  • +
  • -

#18 javabeginner18  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 16
  • Joined: 04-March 11

Re: input-output

Posted 27 March 2011 - 03:47 PM

ArrayIndexOutofBoundExpection :)

This post has been edited by javabeginner18: 27 March 2011 - 03:48 PM

Was This Post Helpful? 0
  • +
  • -

#19 Manbearpig101  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 62
  • Joined: 17-June 10

Re: input-output

Posted 27 March 2011 - 03:50 PM

It's not part of the code that's has an error, it's malformed input.

The second line doesn't have 57 characters in it (including spaces).

I'm not sure about other lines, and I won't count everything, but the code is fine.
Was This Post Helpful? 1
  • +
  • -

#20 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: input-output

Posted 27 March 2011 - 06:46 PM

May be you want something like this
import java.io.*;

public class CharArray {

	public static void main(String[] args) {
		StringBuffer contents = new StringBuffer();
		BufferedReader reader = null;

		int nbRow = 0;
		try {
			reader = new BufferedReader(new FileReader("input.txt"));
			String text;

			// repeat until all lines is read
			while ((text = reader.readLine()) != null) {
				nbRow++;
				contents.append(text).append(System.getProperty("line.separator"));
			}
		}	
		catch(IOException e) {}
		char[][] digit = new char[nbRow][];
		String[] line = contents.toString().split(System.getProperty("line.separator"));
		for(int i = 0; i < line.length; i++)
			digit[i] = line[i].toCharArray();
	}
}


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2