.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
.
Last edited by An6ie; December 10th, 2021 at 07:43 AM.
Please explain.it doesnt play as it should.
Post the program's output that shows what you are asking about.
One big problem is the end of the source code is missing.
Please edit your post and wrap your code with code tags:
[code]
**YOUR CODE GOES HERE**
[/code]
to get highlighting and preserve formatting.
If you don't understand my answer, don't ignore it, ask a question.
This is the output with examples
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
1 2 3 4 5 6 7
2
| | | | | | |
| | | | | | |
| | | | | | r |
| | | | | | |
| | | | | | |
1 2 3 4 5 6 7
3
| | | | | | |
| | | | | | |
| | | | | y | r |
| | | | | | |
| | | | | | |
1 2 3 4 5 6 7
You Have Won!!!
OK, thanks for that. Can you explain what is wrong with that output?
Add some comments showing what the expected output is.
If you don't understand my answer, don't ignore it, ask a question.
When you type '1' to place the counter in number '1', the code executes' it in number '5'. None of the numbers correspond to their correct position. Also, to win the game you should connect 4 counters vertically or horizontally, but the code executes "you have won" after just placing 2 counters down randomly.
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
1 2 3 4 5 6 7
Input: 2
| | | | | | |
| | | | | | |
| | | | | | r |
| | | | | | |
| | | | | | |
1 2 3 4 5 6 7
Input: 3
| | | | | | |
| | | | | | |
| | | | | y | r |
| | | | | | |
| | | | | | |
1 2 3 4 5 6 7
what is should be
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
1 2 3 4 5 6 7
Input: 2
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | r| | | | |
1 2 3 4 5 6 7
input: 3
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | r|y | | | |
1 2 3 4 5 6 7
Ok, Now how are you going to debug the code to see why the values are incorrect?
I use print statements to show the values of variables as they are used and changed.
Look at the code to see what values in what variables will cause it to print: You Have Won!!!
Then back trace in the code to see why those variables have the values they have.
One of the first changes I recommend for the code is to add comments.
Another change would be to the names of the variables used to index into board.
instead of using i and j use row and column
board appears to be an array of 6 rows with 7 columns in each row.
To index into board, code it like this: board[row][column]
If you don't understand my answer, don't ignore it, ask a question.
Thank you for your help, but I think this is too tricky for me to do
Moved out of section where posters are trying to fix their code.
If you don't understand my answer, don't ignore it, ask a question.