Ken Perrine

Greenhorn
+ Follow
since Oct 25, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ken Perrine

Campbell Ritchie wrote:You should have used the code button; I have gone back to your code and used it, and you can see how much better it looks.
What’s a 2D array? It doesn’t exist in Java. What you have is an array of arrays, which is actually better than a 2D array.
How do you know your array will have 154 elements? If you only have 153 lines, you are going to run out of lines. The 154th will be null if you use a BufferedReader.
How do you know each line will have 13 elements? Why, if you are splitting the line to get an array, don’t you simply reassign the line to the corresponding element of the outer array?
Why have you got your little text file in the root directory of C?
Why does your matrix contain only Strings? I though a matrix contained numbers?
Have you come across the syntax to test whether a line is null? It is peculiar and you would never guess it in 100 years:-



I'm not sure if this is how I reply, but here it goes:
I'm a NOOOOBIE-- didn't know about the code button, will use if from now on.
My 2D array has a fixed number of 153 rows and 13 columns, each consisting of FP numbers (I'll convert them later-- for simplicity I just wanted to see if I could read in the array). I know the 154 element is null, that's why I'm trying Buffered Reader with an Exception.
I'm not sure what you mean by an "outer" array. In VB and before, you had arrays of the type (xx,yy), so the "array of arrays" is confusing. I will have a lot of data (.txt) files in an (xx,yy) arrangement to read in.
The text file with the data of the array being read is on the root directory for simplicity, as I am trying different permutations and the directory seems to change with each change in code-- it's so I know it will read and not get kicked back for "not found". I'll work on keeping it in the correct directory later.
Yup, I know about the null, but I thought the BR with Exception did the same thing.
So, I'm still not sure why the last 2 lines of code aren't run--???
Thanks,
Ken
11 years ago
I'm having problems reading in a 2-D matrix. It reads in OK, but 2 problems arise. See below.
THANKS
Nooooobie Ken



Output is OK except:
1. An exception is thrown part way through: “Exception in thread "main" java.lang.NullPointerException at read2d.Read2d.main(Read2d.java:13)”
It is thrown at different places each time I run it, and sometimes the exception is split between 2 disparate locations on the output. However, it doesn’t affect the matrix itself.
2. The output does not print a line break or “fin”.

11 years ago
That is the fastest response I have ever received! And the most concise, vs. my logorrhea... Yes, it is what I was looking for, and much easier than expected. Thanks.
11 years ago
First, I like the rules required for this forum!
I am new to Java.
I am re-writing some very old QBasic DOS programs to Java (and have programmed other things in VB6). In the older DOS versions you could use a READ statement followed by a matching number of DATA text/FP/integers rather than reading in from a file. I couldn't figure out how to do it in VB6, and now can't figure it out in JAVA. For some routines where I'm reading in an array of, say, x(5,4) numbers, it would be easier to imbed in the program rather than writing a text file and having the program read the file.
Can one do it in Java? How, or an brief example?
Thanks,
And have an Old Moosedrool beer (Bozeman microbrewery) on me if you know,
Ken
11 years ago