D diller

+ Follow
since Nov 15, 2007
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by D diller

Yeah it was something along those lines exactly, just figured it out actually. Thanks for the tips!
13 years ago
So I finally have my program nearly running, but am having some problems with getting my multiplication to work properly:

I think it's a problem with carrying, and it throws my numbers off quite a bit...sometimes. Smaller numbers, where you don't have to carry or only have to carry a few places, it's no problem. But for some reason once you get into carrying quite a bit, it's a huge problem. It's difficult to debug it because it requires going through some LONG multiplication. So I am hoping somebody will be able to spot something in my code that I can't.


(For example: 123*456 yields 41310108 when it should be 56088 - that's a pretty significant 'carrying' error!)
13 years ago
Wanted digits = 4 like it would if I converted from a String.
13 years ago
I am having a heck of a time converting from a char to a byte - probably because chars are two bytes...

In either case, whenever I try to convert I get the ASCII value of the character.

if aChar = 4, I get 52 for the value of digit, which is the ASCII value of 4.

Any clues?
13 years ago
He went over it a bit for the powers, so I'm not too worried about that - and I would use an int[] but he's already specified to use a byte[]. Oh well...

Thanks for the tip on % though.
13 years ago
Homework assignment, can't. My professor for some reason thinks that making us do the hard things instead of using what's already available to us is the best way to teach us.
13 years ago
Hey -

I am trying to write a program that takes an input of a file formatted as such:


etc, where after number1 there is a sequence of number -- operator. Then the math for doing it should be number 1 (operator 1) number 2 = new number
The problem is that these numbers are far too large to use an int, probably even a float once you get down to many operations including powers. So I would like to use an array of bytes in order to calculate the number correctly.

My problem is that I have absolutely no idea where to start. Can anybody give me any pointers?
13 years ago
Nevermind, I figured out a way around it - I will just put all the following data after the first line into the array, and store the first line (which is just an int value that says the number of lines after it) in a different public variable. Just did it, works like a charm!

I am trying to load a file and put its data into an array so that I can more easily use it; that's not really presenting a problem, as I can get that just fine. What I'm encountering is that when I try to extract a specific set of chars using a StringTokenizer from each element in that array I get some funky results.
This makes the array, but I can't use it how it is. I need to make it one element longer. Each time I do, though, I get a null pointer exception. (that's if I have ).

Here is where I'm using the StringTokenizer:

The last value of the array returns null (default value) which isn't that much of a surprise, since I'm making it one longer than my libraryFile array.

If I change the length of my libraryFile array to the proper size, I get a null pointer exception on the StringTokenizer.

So my issue, basically, is that I can't get my original array to be sized properly. Does anybody know why, or have any tips?>
13 years ago
Never mind, I actually figured out how to solve my own problem efficiently - at least as efficiently as I can think of right now. I know how many entries (lines of text) there are because that's the first line in the text file, so I can make one array that length. I can then store all the matches in that array and keep a running count of matches. After I go through the entire file, I can just instantiate the final array with a length equal to the number of matches I counted. After that, it's simply iterating through the original array and copying values only until the index I'm on is equal to the number of matches I counted. This will fill the array completely with what i need with no extra fluff and nothing missing!

If anybody can see any problems with my logic here, please let me know!

13 years ago
Here's the situation:

I would like to run a type of search function on a text file using StringTokenizers. If the user-inputted value is equal to a specific token (for example, always the first token of a line), then the third token of that same line should be added into an array.

The problem I am encountering is that I don't if it's possible to add data to an array before its length has been declared (and thus the array isn't even instantiated), and I can't have extra elements at the end; nor can I be short on elements - its length must be exactly equal to the number of matches in the text file. It has to be able to handle any number of elements. Also, I would like to not have to add a number to a count and then go back through the file again to get the third token (since StringTokenizers are only good for one token), as that's really inconvenient and inefficient.

Is there any way that you guys know of that I can somehow efficiently do this? Any sort of guidance at all would be very appreciated.
13 years ago
I'm trying to load an image and convert it to a 3D int array like array[z][x][y] where z corresponds to the red, blue, or green value of the image, x refers to the row of a pixel, and y refers to the column of a pixel. I then want to be able to add various filters (sharpen, etc) to the array and redisplay the image - I'm not worried about that right now though.

I've been searching for the past week on how to convert an image to a 3D array, but I have come up empty handed. Any tips would be greatly appreciated.
13 years ago
Alright, got the code to run now; still not complete for how it should be, but it'll do.
13 years ago
Finally finishing up that program that I got a bit of help on the other day, and it's coming together quite nicely except for one problem - when I click on my 'Next' button, nothing happens.

I have a 2D array of type Boolean which I randomly disperse 'True' values around in. It works great, and I can create an array of any size pretty much and have any number of elements be true or false. The 'Next' button will eventually be different than this, but it's like it's not executing at all.

That's for the 'Next' button, and my nextGeneration:

I realize that all my 'Next' button should do is just make all the values of my array false, and I have another button that does that and it works - in fact, I just copied and pasted that code. So can anybody give me any pointers/things to look for? I'm dumbfounded.

Side note: What does "String[] args" mean? like if I had 'public void nextGeneration(String[] args){' instead>
13 years ago
I'm now having some problems with getting my GUI to display properly - I've looked over all the code I can think of but I just can't narrow down what my problem is.

And the code for the GUI in the only spot I change the color of any cell:
It calls on life.isAlive:
So, simply, it returns true if it's true or false if it's false. No if statements or anything to return; even if I change this to return false; I get the same result.
Does this code look okay for going through and setting a specific number of true values? I tested it on a 3x3 array with numtolive = 2, and it seemed to work fine; my GUI displays all as 'true' though, even if I know 100% for sure the value is false (as in I set everything to false, and even if I didn't the default boolean value is false)

13 years ago

Campbell Ritchie wrote:

D diller wrote:if (board[x][y] = true)

Henry has already commented, but the correct format would be

if (board[x][y]) . . .

Erm, shouldn't I haveinstead of? Won't it error out on the second way?
13 years ago