Venny Tank

Greenhorn
+ Follow
since Jul 20, 2011
Venny likes ...
Chrome Java Ubuntu
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
7
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Venny Tank

Manoj Kumar Jain wrote:as I can see in your logic it has a bug. when


will check that the random no. generated is not equal to the current item in the array numbers[i] and onwards but what about the previous items ??. It doesn't consider the case in which it can be equal to the previous item in the list that is already checked.

for example take the case that you first generated the random no. as 22 in the for loop and then you generated the no. 10 in the while loop



I'm still on single dimensional arrays chapter of the book that I'm learning from and can't use any more advanced techniques than that.
Is there any way I can check the random number against previous items?
9 years ago
Hi, guys
the task is:

Write a method that returns a random number between 1 and 54, excluding the numbers passed in the argument.
The method header is specified as follows:


The code I've wrote:


The end result for the random generated number should be a value different from the numbers in the array.
In this code I've managed to generate new random if the generated number is equal to one of the numbers in the array, but can't figure out how to test the new value again.
Could you point me the right direction to find my mistake?

Thanks a lot
9 years ago
Hi,
I'm writing a program that displays first 100 emirp numbers (emirp is a nonpalindromic prime number whose reversal is also a prime). In my code I have an IF statement that invokes methods that return boolean values, like this:

The same result can be accomplished if these boolean values are assigned to boolean variables, like the example below:

My questions are:
Invoking methods in statements or assigning their values to a variable first?
Which is better from a real life programming prospective, what is the usual practice?

Thank you!
9 years ago
Thanks everyone

Joseph Tulowiecki wrote:You would have to use while ( (userWins < 2) && (compWins <2)){

instead of ||

when you use " || " your saying .. Continue looping as long as either the user has less than 2 wins or the comp has less than 2 wins. This will never stop looping because it is Always true. If the computer has two twins then user has 0 wins and vice versa so one of them will always have less than 2. Therefore the loop will never end. If you use && which means "and" it will give you the results your looking for.



Very well explained why the code:

never stops looping in my code, now I understand

Thanks again
9 years ago
Thank you all of you guys for the suggestions!
I learn java (with no previous programming experience) on my own by reading the java's documentation, and a book following the exercises.

@Joe, @Campbell: Yes, I'm still on the chapter about loops, so don't know too much about methods yet, but will keep in mind and try not to develop bad programming habits.

I've tried avoiding the WINNER variable by using only:

but it keeps going to generate random number and asking for user input even if somebody has a score of 2 and more.
And my question now is: May I use a "while" loop with two conditional statements like the code above?

I'll read further about enums and using methods.

Thank you all for your help
9 years ago
The task is to write a program that plays the scissors-rock-paper game. The program should let the user continuously play until either the user or the computer wins more than two times (I assume in a row).
I'm confused about the while loop in the code I wrote:



I've tried to use



instead of how it is in the code, but that doesn't seem to worked as I've expected. It keeps looping no matter how many times user or respectively computer won.
Any suggestions how to write the program better are greatly appreciated.
9 years ago
I'm also a java beginner, and on the same boat as you Darrin,
just stuck on the same exercise and after an hour trying write some code myself that didn't work, found this forum and read some other sources also.
So this is what I came up with, don't know if it is the right way, but it's working.



actually it is not the complete program from the exercise, it should check first if the integer (n) entered from the user is positive.
and also I think there is another approach to this exercise:



the problem is when enter a negative value, my positive value checker is not complete
10 years ago