Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!

Josh Theisen

Ranch Hand
+ Follow
since Sep 23, 2011
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 Josh Theisen

Thanks for the replies, everyone.
As some of you may have guessed, this is for educational purposes, but we are not limited to using only regex. I had thought that regex would have been the easiest way to
check for predicates (for, if, else, else if, etc). From what I've gathered, it would be best to write a separate parser for this type of problem.

6 years ago
Hey everyone. I've pasted my little project I"m working on so far... I have a text file of some code and I need to go through it line by line and
find all of the for loops in it. I've got it so that I can go through all of the lines, but I'm stuck on the regex part. Basically, if the line has "for" followed by a left parenthesis, it should qualify as a for loop. If it qualifies, it should print out that line.
I tried using but that obviously doesn't work in all cases since the word for can be used in comments, or other strings.

I've tried looking up what would be the correct regex expression but I'm not coming up with much.


6 years ago

R. Jain wrote:

I did try that code and it didn't work. However, I fixed the problem by simply adding a name to the
input submit button and called a .getParameter on that. Thanks!
7 years ago
Going to make a separate reply here since I think this will help clear up what I need it to do. For each of the form buttons, I would need something like this.

Notice that the very first line gets the parameter name. However, from the little reading I've done, request.getParameter won't work for forms - only inputs.
7 years ago
Hey guys ... The school year has started again, so that means I'll probably be back here!
I'll cut to the chase: I have two forms in a single .jsp file. I'd like to make it so that if I hit one button, it'll do some java. If I hit the other one, it'll do the other stuff. Right now, whenever I hit one button, it does everything.

Here's what the .jsp file looks like so far. At the bottom of the page I'll "highlight" where I think I need to work.

Here is the first form:

I need to make it so that when I hit that submit button, only this code here is called:

If you guys want any more information, I'll gladly give it. Been working on this for a while now and just can't seem to get anywhere.
Thanks everyone.
7 years ago
Thanks for all the replies. So just to make sure I'm understanding this correctly ... in my example, the 2nd number (coming down from 1/15000000) will be more accurate since it has more significant digits due to the way that floats truncate?
7 years ago

Jeff Verdegan wrote:Did you try it? Did you get different results?

I did - the second result was increased by 1, which is what I thought would happen.

Jeff Verdegan wrote:So, what do you think will happen if you add 0.0001 to 123,456,789,000? And what do you think will happen if you add 0.0001 to 0.000123456789?

If you ad .0001 to the first number you mentioned, it wouldn't do anything if I'm understanding it right. However, in your 2nd example, .0001 would get added no problem and change the value.

So in my case... if I'm understanding it correctly, the 2nd value should be more accurate.
7 years ago

Paul Clapham wrote:Actually, your second result is incorrect.

Whoops - guessing the 2nd for loop needs to be "for (float i = second; i >= 1.0f; i--) { "
Greater than or equal to one instead of 1...
7 years ago
Hey guys - so I was asked to do a little assignment here... and we're supposed to use the data type float (32 bit floating point).

Here's the assignment: write a program so sum the following sequence:

1.0/1.0 + 1.0/2.0 + 1.0/3.0 + 1.0/4.0 + ... + 1.0/x, where x = 15,000,000.0

Then I'm supposed to loop through it again, but this time, backwards. i.e. (1/15000000.0 + 1/14999999.0 + ... + 1/1)

So I've done that (I think) as seen here:

When going up, I get 15.403683, when going down, I get: 16.117563
Now I know the values are supposed to be different (teacher told us that), but I'm not exactly sure why.

We are also supposed to say which of the two sums is probably the most accurate ...

Guess I'm not sure which one would be more accurate than the other.

7 years ago
I think that the set/collection will work -- thanks.

Another question, even though it's not directly related ... say I'm going through this string character by character...
In this string there are numbers. I'll also be using a stack... if I find numbers I'll push them on to the stack - however, when
I pop them off I want it to act as a single int/number.

For example, I come across a 1 - push. The next char is a 2 - push to stack. When I pop 2 and then 1, I want it to be the int 12. Is that possible?

7 years ago
Alright, the title may be a bit misleading but I have no idea how else to phrase it.
I have an array of type char, and it contains 5 characters (say '1','2','3','4','5').

Next, I'll be going through a string one character at a time... if it's one of the above characters, I
want my program to do something else - is it possible when I'm going through my string to check
the array to see if it's one of the characters? Or do I have to do this the "hard" way with if/then checks
or switch statements?

7 years ago
Hey guys - so not a programming problem here, but one that I just can't seem to figure out.

In my notes, it says,

A binary tree of depth d is almost complete if:
1)Each leaf in the tree is either at level d or at d-1
2)For any node n in the tree with a right descendant at level d,
all the left descendant of n that are leaves are also at level d.

Here are two examples:

The first one, according to my notes, is not almost complete because: "Since A has a right descendant J at level 3, but it has a left descendant E that is a leaf at level 2"
I think that makes sense.

However, for the second one...we didn't get an answer. But, from what I can tell, we have a right descendant F at level 2, and at least all the leaves on the left are at level 2 - so that would be an almost complete binary tree.

Am I even thinking straight here? Finals week...brain's almost fried.

7 years ago
Hey guys... so I'm working on a little program to show all the different edges for a graph.
Example: ***ABCD would have the outputs: *AB, *AC, *AD

I don't need help with the actual code as of now... but whenever I try to print, I get 173 instead of
the expected *AB.

Can't say I've seen this before either, so I'm wondering what the heck is going on.

7 years ago
Thanks for all the replies. I found out that my teacher might have wanted me to do it a different way...
With my own Node class and pointers. But if I can do it this way, I'll definitely refer back.

7 years ago