• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading integers into a 2d array for nQueens so to be implemented in program  RSS feed

 
leo porta
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently trying to use IO command to read 3 inputs from a txt file, first one being the size of the board (both row and columb spaces) second integer would tell row and the third integer column (or vice versa).



Been trying to get this to work for some time and would really appreciate all the input provided into letting me know how this one could work so that the program reads the 3 numbers, runs the recursion and then outputs the solution coordinates on the txt

 
Carey Brown
Saloon Keeper
Posts: 3311
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is this "IO command" of which you speak?
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Who told you that you have a 2D array? There is no such thing in Java®. What you have is an array of arrays, which is different (and better).
Why do you need to read values into an 8 queens puzzle in the first place? You usually only need a starting square in the first file, and you can iterate from 1…8 (or 1…n) anyway. Maybe the easiest way is to use a Scanner object pointing to System.in. You can find a basic example (without error checking or validation) in the documentation for Scanner. It is also possible to use a Scanner to read from a text file. Keep reading the documentation for more information; you can probably simply use the nextInt() method thrice. Beware: again there is no validation or error handling shown.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!