Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone help me with my code please. I posted my code below. I keep getting an error GFG.java:115: error: array required, but String found

can someone help me with my code please. I posted my code below. I keep getting an error GFG.java:115: error: array required, but String found boggle[i][j] = line[k]; some help me fix this. and this code is to solve the boggle game. it's suppose to read a dictionary file and a board of 4x4, 5x5, 10x10, and more. Did i do it right to read those files? Can someone help me please. Thank you!

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

class GFG {

static int row[] = {0,0,1,-1,-1,1,-1,1};

static int col[] = {1,-1,0,0,-1,1,1,-1};

public static void find(String d[],int mat[][])

{

boolean flag = false;

boolean visited[][] = new boolean[3][3];

for(int i=0;i

{

for(int k=0;k<3;k++)

{

for(int j=0;j<3;j++)

{

visited[k][j] = false;

}

}

for(int p=0;p<3;p++)

{

for(int q=0;q<3;q++)

{

if(mat[p][q]==d[i].charAt(0))

{

//System.out.println(p+" "+q+" ");

if(findutil(d[i],mat,p,q,0,visited))

{

System.out.println();

flag = true;

break;

}

}

}

if(flag == true)

{

flag = false;

break;

}

}

}

}

public static boolean findutil(String str,int mat[][],int i,int j,int m,boolean visited[][])

{

if(m==str.length()-1)

{

System.out.println(str);

return true;

}

if(m>str.length()-1)

return false;

for(int p=i+0;p<8;p++)

{

if(i+row[p]>=0 && i+row[p]<3 && j+col[p]<3 j+col[p]>=0 && visited[i+row[p]][j+col[p]] == false &&

mat[i+row[p]][j+col[p]]==str.charAt(m+1))

{

//System.out.print(str.charAt(m+1)+" "+(m+1));

visited[i+row[p]][j+col[p]] = true;

findutil(str, mat, i+row[p], j+col[p], m+1,visited);

}

}

return false;

}

public static void main (String[] args) throws FileNotFoundException {

// I am not sure of how the words are placed in the dictionary.txt.

// Is it comma seperated words OR one word per line.

// below I assume one word per line and store the same in the dictionary[] array.

//creating File instance to reference text file in Java

// provide the correct path to the dictionary.txt file.

File text = new File("C:/temp/dictionary.txt");

//Creating Scanner instnace to read File in Java

Scanner scnr = new Scanner(text);

String dictionary[];

// assuming the first line will give the number of words in the dictionary.txt

dictionary = new String[scnr.nextInt()];

while(scnr.hasNextLine()){

int i =0 ;

String line = scnr.nextLine();

dictionary[i] = line;

i++;

}

// lets read the 4x4 Board.txt file.

text = new File("C:/temp/Board.txt");

scnr = new Scanner(text);

int boggle[][];

int leng = scnr.nextInt();

boggle = new int[leng][leng];

int i = 0, j=0;

while(scnr.hasNextLine()){

String line = scnr.nextLine();

int k = 0;

for( j=0;j

boggle[i][j] = line[k];

k = k + 2;

}

i++;

}

// String dictionary[] = {"GEEKS", "FOR", "QUIZ", "GO"};

//int boggle[][] = {{'G','I','Z'},

// {'U','E','K'},

//{'Q','S','E'}};

// find(dictionary,boggle);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

Students also viewed these Databases questions