Join Carlos Rivas for an in-depth discussion in this video Scanning for solution, part of Code Clinic: Java.
- Before we can understand why…such a small data structure of eight numbers…can help us represent our problem,…we need to make a couple of assumptions.…Because we're trying to place…eight queens on the board,…and they would attack each other…if placed on the same row,…each row will contain exactly one queen, and no more.…The same can be said about columns.…Exactly one queen per column.…So, in our loop,…starting on line 17,…the first thing we do is validate…if the current chess board…is valid up to the current row.…
We will look at the code for row validation shortly…but for now, let's continue down the main loop.…As we continue to get valid results…from our validation function,…we continue on to the next row…and restart the column count at zero,…seen here on line 21.…If we get eight rows,…that means we found a solution,…seen here on line 24.…In this if statement,…we also take a moment to print…that we found a solution,…and we print the board to the screen…in a human readable format.…
We will write the code to print the board shortly,…
Visit other courses in the series to see how to solve the exact same challenges in languages like C#, C++, PHP, Python, and Ruby.
Skill Level Intermediate
1. Problem 1: Pond Oreille
2. Problem 2: Where Am I?
3. Problem 3: Eight Queens
4. Problem 4: Accessing Peripherals
5. Problem 5: Facial Recognition
6. Problem 6: Real-Time Information Dashboard
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.