Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.PrintStream;
- import java.util.Scanner;
- public class WordSearch {
- public static void main(String[] args) throws Exception {
- Scanner sc = new Scanner(new File("puzzle.txt"));
- // reading in rows and columns for the array
- int numRows = sc.nextInt();
- int numCols = sc.nextInt();
- // creating an array for the puzzle
- String[] stringArray = new String[numRows];
- // reading in the puzzle array
- for (int i = 0; i < numRows; i++) {
- stringArray[i] = sc.next();
- }
- // reading in number of words to find in the array
- int numWords = sc.nextInt();
- String[] wordArray = new String[numWords];
- for (int i = 0; i < numWords; i++) {
- wordArray[i] = sc.next();
- }
- // this will get the word to find in the array
- for (int i = 0; i < numWords; i++) {
- String wordToFind = wordArray[i];
- }
- // iterating over the array to find words
- for (int x = 0; x < numRows; x++) {
- for (int y = 0; y < numCols; y++) {
- }
- }
- sc.close();
- }
- // this method will be used to check for the words
- private static boolean wordCheck(String puzzle[], String wordToFind, int xpos,
- int ypos) {
- for (int i = 0; i < xpos; i++) { // along x axis positive
- if (puzzle[i].charAt(xpos) == wordToFind.charAt(i)) {
- //System.out.println("Finding word");
- return true;
- } else {
- //System.out.println("Couldn't find the word");
- return false;
- }
- }
- for (int i = 0; i < ypos; i++){ // y axis positive
- if (puzzle[i].charAt(ypos) == wordToFind.charAt(i)){
- //System.out.println("Finding word");
- return true;
- } else {
- //System.out.println("Couldn't find the word");
- return false;
- }
- }
- for (int i = 0; i < ypos; i++){ // negative x axis
- if (puzzle[i].charAt(xpos) == wordToFind.charAt(i)){
- //System.out.println("Finding word");
- return true;
- } else {
- //System.out.println("Couldn't find the word");
- return false;
- }
- }
- for (int i = 0; i < xpos; i++){ // negative y axis
- if (puzzle[i].charAt(ypos) == wordToFind.charAt(i)){
- //System.out.println("Finding word");
- return true;
- } else {
- //System.out.println("Couldn't find the word");
- return false;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement