Sergiu Dobozi

Ranch Hand
+ Follow
since Oct 26, 2016
Sergiu likes ...
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 Sergiu Dobozi

I also have a problem with this program.
The first line contains "return j". However j is not declared anywhere yet. No compilation error whatsoever even in the second line where the method is executed with "static int i=peek()". Only in the third line does the declaration occur simultaneous with the initialization, what is the logic then that the program should return 0 if j was not declared at the moment that peek() is executed?
The only explanation I can find that works is that the compiler first creates all the fields necessary for the class to work and after that it reads the methods and executes them in the written order with the default values.
2 years ago
The program rolls two dices 4 times. If I keep the skip method the program will wait for me to press enter and roll again. If I pull out the skip method and replace it with continue, the program waits for me to press enter but then rolls the dice 3 more times, it asks me to press enter and the game is over.
What does then really do?
If I delete it entirely and don't put continue instead, the program will roll the dice, ask me to press enter, roll the dice twice, ask me to press enter, roll the dice and finish (it still asks me to press enter but will not wait for my input).
2 years ago

Piet Souris wrote:
Anyway, rest assured: I won’t tease you any further ;)

Thank you, you asked me really great questions  
2 years ago

Knute Snortum wrote:This is why I consider poor formatting a bug.  You wrote this:
Is that what you intended?

Yes, sorry about that. I don't know why I wrote the if the other way around.
2 years ago

Piet Souris wrote:First of all: have a look at the method 'differByOne'. If the two strings are equal, what does the method return?

Then: it is not guaranteed that all array elements are equal in length, just that each has length between 2 and 15. What implications does tht have for your code?

And about 'findSequence': it is much more efficient than the original, indeed. The problem is that if, somewhere in the loop, 'success' becomes true, then the loop is still fully executed.

I took the liberty to write a simple application, that makes testing a little esier.

Now, the array used here is {"ag", "bc", "aa", "bb", "ab", "cc"}. Since this array can indeed be successfully arranged, you would expect that 7 calls to 'findSequence' would suffice (one call for n = 0, n = 1, ..., n = 6).
As you see, your second code is much more efficient that the original version., but it is not optimal yet.

Ok, so I am at work right now and downloaded BlueJ since we are not allowed to install software like Eclipse or IntelliJ (I work as a simple data analyst).
I realized I should just move the if(!success) condition right above the method (line 68) as it attacks it directly and now we only have 7 calls to it, it's almost completely optimized.
Now it should be fine for two equal strings (it should return false) but when I wrote the code like this before:

then the two equal strings would return true and that's not what we would need.
Finally, if even one string would have a different length from the rest then this program should return false, I haven't thought about it before. I think this deserves a new method of its own?

2 years ago

Piet Souris wrote:hi Sergiu,

There are some easy improvements possible.

All that is required to detect if a rearrangement is possible, is to see if 'success' is true in the end. Now, if you look at the 'findSequence' method, you will notice that the recursion goes on, even if 'success' has been put to 'true'.
Can you make a small change so that the method returns when that happens, without going into the recursion again?
(You can check the number of calls to the method 'findSequence' if you add a second field to your class, say int counter. Add as the first line in this method: counter++; and when done, print that variable).

In the method 'differByOne' you compare all the chars. What can you say about the outcome when, after the second comparison, count is 2?

If the count is 2 there is no need to go any further so it should return false. I changed that.
I am still working out the recursive backtracking in my brain, so I added a stop condition above the for loop in the first findSequence method, using my intuition rather than hard solid knowledge. Let me know if it's right or wrong, please :-)

2 years ago
I have stumbled upon some code that uses a recursive algorithm (backtracking?)
I am trying to figure out mentally how this would work for the simplest input.
The problem that this code solves is below:

[Given an array of equal-length strings, check if it is possible to rearrange the strings in such a way that after the rearrangement the strings at consecutive positions would differ by exactly one character.


   For inputArray = ["aba", "bbb", "bab"], the output should be
   stringsRearrangement(inputArray) = false;

   All rearrangements don't satisfy the description condition.

   For inputArray = ["ab", "bb", "aa"], the output should be
   stringsRearrangement(inputArray) = true.

   Strings can be rearranged in the following way: "aa", "ab", "bb".

   [time limit] 3000ms (java)

   [input] array.string inputArray

   A non-empty array of strings of lowercase letters.

   Guaranteed constraints:
   2 ≤ inputArray.length ≤ 10,
   1 ≤ inputArray[i].length ≤ 15.]

Even thinking of the simplest input [q,q] that should give false, I cannot imagine this, what's the order of instructions?
And why used[i] = true; and then used[i] = false; ?

2 years ago

Stephan van Hulst wrote:Plugin for what, your browser?

I don't think Java is very useful for this. Most browser plugins are written in JavaScript. Check out this article for more information:

So to explain better, I would copy-paste the video URL from my browser to my created desktop application and the application would tell me that it has compiled all video comments into a Word Document and ask me if I want to save it to my Computer. I would then have to click on OK or Cancel. Is this possible with Java and what other technologies would I need to learn?
3 years ago

Stephan van Hulst wrote:Plugin for what, your browser?

I don't think Java is very useful for this. Most browser plugins are written in JavaScript. Check out this article for more information:

Hmm, I learned the wrong language then :-)
Maybe a java desktop executable can do the same thing? I would open the software introduce the youtube URL and the executable would return all the comments in a DOCX file. Would that be possible?
3 years ago

William Ng wrote:First step in a project is to define exactly what you are trying to do. Your post is a bad example. It is missing a lot of details and makes it hard to understand what you mean. As one other posters mentioned, what do you mean by "plugin"?

I stated the problem and end-result. I am curious if I can, with the help of the Java language, display all comments from Youtube on my web browser. It can be an executable program, not necessarily a web-plugin. I kind of see that Javascript is better suited for this problem.
3 years ago
Hi guys,

I've been learning Java for about 9 months now (on and off) and now I'm ready for a project. I've got a good idea but don't know how to get to implementing it.
Is it possible to make a plugin that will show all comments on Youtube videos? Right now when I click on more comments, Youtube only loads 10 comments and I want the plugin to load another page with all comments.
What is the next technology to learn after Java Core?
3 years ago

Danny Alphones wrote:i am sorry i am a real beginner to java so when you say "you will write the code that prints out the results generated in the previous methods." i have no idea how to do that i just started java a few weeks ago i consider it a miracle that when somebody talks about a scanner or a if statement or a for loop or while loop i know half of what they are talking about.    

Okay so then your first step before you even consider solving the problem is understanding how to write methods, what they are...same goes for basic stuff: learn about if statements and loops. Then you can come back with real knowledge to solve this problem and post your solution in this thread.
3 years ago

Danny Alphones wrote:

Now you create the smallest and largest fields and write the logic behind each step. It's going to be a fun ride, don't worry.

what do you mean by Smallest and larges fields and write the logic behind each step
could you show me an example of that.

I mean you should define two fields named Smallest and Largest.
The logic behind steps means the code inside each method. You should basically replace the  // TODO Auto-generated method stub with your own code in each method. For example in printResults() you will write the code that prints out the results generated in the previous methods.
3 years ago