This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!

Safi Habib

Greenhorn
+ Follow
since Apr 12, 2019
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 Safi Habib

Thanks all!

After looking at it soem more with other peers it seems that the solution is that if the 2nd number appears twice (once before num1 and then again after) it will return NO.  So to fix i have changed the 2nd loop so it starts from the end of the array and goes backwards so that num2 index is always higher than num1 index
1 week ago
Hi There
I have written the below code and am being told that it will not always work by my lecturer but i dont understand how? every format of array i have tried comes back with "YES".....  the condition of the method was that num1 index is always lower than num2 index and both num1 and num2 always must exist in the array i input.

Anyone have any advice, it would be appreciated!

1 week ago
Thanks for the advice...i did think about methods but the lecturer said for this exercise we can get away with it all in the main method, thats why it looks like this!

I have corrected it so it checks the length and also my lecturer advised that the order of things happening needed to be looked at so i have changed that so that it makes more sense.

I have edited my code and it works now but strangely only with long strings.  For example "Networking" and "Assignment" work ok, it returns both halves and checks they match.
But when i type "hello" it only returns "lo" and "he" which off course fails the check that it does.

Why is this happening?!

**Edit** it seems to work only on strings that are even in length, not odd.  Not sure why but something is happening when i build the string with odd lengths that means an empty element is being sent!!

Client code:






Server code:

Hi  
i am slowly learning to code as an evening course.  We have an assignment to code a client application that takes an input string, splits into two halves and assigns them to packets.  These are sent to a server application that then takes the two halves, swaps them round and sends them back to front to the client.  The client then prints the results and confirms if the string returned matches the input string.  I have coded this and it kind of works.  I am stuck on one thing.  For some reason my byte arrays are not resetting after a message is sent from the server and what ends up happening is that it returns the characters from a new string and if this new string is shorter than old string the remaining characters are also returned.  What have i done wrong here?  I suspect it might be cos i have set the byte array on the server to 128 bits so just carries on till it runs out of memory?  If that is case i dont know how to assign a length to the array based on the incoming packet as i declare the array before the packet arrives!  Any advice would be great or indeed a topic i need to revisit in my studies that could explain the issue!

This is the client code:



This is the server code: