This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!

salvin francis

Saloon Keeper
+ Follow
since Jan 12, 2009
salvin likes ...
Eclipse IDE Google Web Toolkit Java
Mumbai
Cows and Likes
Cows
Total received
92
In last 30 days
0
Total given
120
Likes
Total received
270
Received in last 30 days
5
Total given
136
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by salvin francis

Forgive me if the above code has some semantic/compilation errors

0 or negative can be special/corner cases and left out of the loop instead of checking it for every iteration. Once I removed those, it no longer looked like a while loop and hence I made it a for loop.
3 hours ago
Disclaimer, I am not a Jython/Python guy.

Write a program that will read in a number and will output the numbers between 1 and 100 (inclusive) that are divisible by that number



Is the user allowed to enter -888 or 567 or (my favorite) 0 ?

6 hours ago
I think any unidentified flying object is a UFO this can include any streak of light outside the space station. They may not be saucer shaped.
1 day ago

Junilu Lacar wrote:...Not sure where we disagree. ...


A single method isNotThreeDigit() is what I disagreed on since my first post.



1 day ago
I think there are two approaches for the timer delay that I can think of. Both of them involves simply recording the lastExecutedTime. Whenever you do your tick, simply update the lastExecutedTime and also calculate the diff in milliseconds from the last run time. This number is the basis of your calculation :

Cycle/Tick based logic:
Let's assume your "cycle" is 10ms and the difference between last and now is 15ms, then you have to account for 1.5 cycles in your current render. e.g if your ball moves 1 unit every cycle, it should move 1.5 unit this cycle.

Time based logic:
Alternatively, you can work your logic based on time. i.e. decide how much the ball should move given that 15ms has passed. e.g. if your ball moves 1 unit every 10ms, then it should move 1.5 unit for 15ms.
1 day ago

Anduena Smith wrote:


This is particularly an area of interest for me. Your delay method uses a Thread.sleep() to wait for one clock tick. Here's what the java doc say:

javadoc wrote:Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors.


This means that a thread can sleep for slightly different intervals depending on systems and is also subject to their underlying load. Your balls can move faster on a faster machine with no load and slower on a machine with high load. If you are designing a game, you would be interested in that.
1 day ago

Junilu Lacar wrote:...That is quite a stretch of an argument. If you need to negate isNotThreeDigit(), then write a isThreeDigit() method instead. ¯\_(ツ)_/¯  ...


Let's simply agree to disagree

I understand your perspective about keeping code easier to read and I think you understand my perspective about having a single negation method without it's partner assertive method.
1 day ago
Good catch !! It would been better to assign it to a variable and then loop it using for-each loop. Or, use the traditional for loop instead.
4 days ago
I'd agree for a isNotXXX method only if there is a corresponding isXXX method that is present. Having a single isNotXXX method in a code is very confusing especially if in the future, someone needs to negates it:
e.g. if(!isNotThreeDigit()) is very confusing to read. This is also true for natural spoken english, two negatives in a sentence is confusing. "Push button to release oxygen" vs "Do not push this button if you do not want to release oxygen" !!!

4 days ago
Instead of a while loop, you can use a simple for loop and loop through the string characters.

e.g.



Alternatively you can use streams.
4 days ago
On a separate discussion, why would you want your users to type "rock","paper" or "scissors" in the first place ?
Even if you were writing a Command line program, I'd prefer a short-code like:

Enter your choice (1=Rock, 2=paper, 3=scissors) : [Let user type here]

or, if you want to go the swing way:
4 days ago

Junilu Lacar wrote:

I suggest going for a isThreeDigit instead of a isNotThreeDigit method.
4 days ago
If I am reading some code, and I come across a method with a signature as :
public static boolean isNarcissisticNumber

I would assume that this method returns true and false based on the number. Your method also has System.out.print statements. This means that the method is not only deciding, it's also reporting the result. This may be undesirable if you use this same code in some other program.

If we remove the print statements, your code becomes:This can be shortened to:This can be shortened to:or:and finally:

Hope it helps
5 days ago
Junilu mentioned a while ago :

Junilu Lacar wrote:Numbers that have less than three digits: 0-99

Numbers with three digits: 100-999

Numbers with more than three digits: 1000- onwards.

Can you write an if statement to check if a number has 3 digits based on the above information?



I see that your updated code is trying to use this idea but on the wrong variable.
Hint: The if condition would not be on "count" in this case.
5 days ago