Okay so for my search method I have some questions. For some reason when I try to compile it says im missing a return statement. Any idea why?
private boolean sHoriz(int inRow, int inColum)
{
int r = inRow;
int c = inColum;
for (r = 0; r < array.length; r++)
{
for (c = 0; c < array[r].length; c++)
{
if (array[r][c]!=word.charAt(1))
{
return false;
}
else
{
return true;
}
}
}
}
--- Update ---
Nvm sorry I figured it out... finally my program is sorta working/doing something lol here is what I have so far. The assignment is due tomorrow at 8 so I dont expect to get it working by then. Maybe someone will be able to respond here in the next few hours if not thanks for the help you guys did give me!
import java.util.Scanner;
public class WordSearch
{
char[][] array;
String word;
Scanner in = new Scanner(System.in);
public WordSearch(char[][] inArray)
{
array = inArray;
}
public void play()
{
print();
}
public void print()
{
for (int r = 0; r < array.length; r++)//step into array
{
for (int c = 0; c < array[r].length; c++)//look through each spot in array
{
System.out.print(array[r][c] + " ");
}
System.out.println();
}
System.out.println("User, please imput word you wish to search for.");
word = in.next();
Search(word);
}
private void Search(String inWord)
{
word = inWord;
boolean found = false;
for (int r = 0; r < array.length; r++)//step into array
{
for (int c = 0; c < array[r].length; c++)//look through each spot in array
{
if(array[r][c]==word.charAt(0))
{
if(sHoriz(r,c)==true)
{
System.out.println("The word was found!");
found = true;
}
if(sHoriz(r,c)==false)
{
System.out.println("The word was not found!");
}
}
if(array[r][c]==word.charAt(0))
{
if(sDia(r,c)==true)
{
System.out.println("The word was found!");
found = true;
}
if(sDia(r,c)==false)
{
System.out.println("The word was not found!");
}
}
if(array[r][c]==word.charAt(0))
{
if(sVert(r,c)==true)
{
System.out.println("The word was found!");
found = true;
}
if(sVert(r,c)==false)
{
System.out.println("The word was not found!");
}
}
}
}
}
private boolean sHoriz(int inRow, int inColum)
{
int r = inRow;
int c = inColum;
for (r = 0; r < array.length; r++)
{
if (array[r][c]!=word.charAt(1))
{
return false;
}
else
{
}
}
return true;
}
private boolean sDia(int inRow, int inColum)
{
int r = inRow;
int c = inColum;
for (r = 0; r < array.length; r++)
{
if (array[r][c]==word.charAt(1))
{
return false;
}
else
{
}
}
return true;
}
private boolean sVert(int inRow, int inColum)
{
int r = inRow;
int c = inColum;
for (r = 0; r < array.length; r++)
{
if (array[r][c]==word.charAt(1))
{
return false;
}
else
{
}
}
return true;
}
}
Output for one run:
"f q e x f e c m x d v j l g u
c x o m f s l i e y i t q t z
n u c a t f a k u x o f e g k
h f y t p n s d l h c o r e y
p g r h d q s y p y s c p e d
c k a d h y u d t i o a p j e
y e r j o d x n q z z t f m f
h y p m m g o r o n k z h u o
h d s k y m m p k z o k a a o
a m u e w q v t m r l g l a d
User, please imput word you wish to search for.
cant
The word was not found!
The word was not found!
The word was not found!
The word was not found!
The word was not found!
The word was not found!
The word was not found!
The word was not found!
The word was not found!
The word was not found!
The word was found!
The word was found!
The word was not found!
The word was not found!
The word was not found!
The word was not found!
The word was not found!
The word was not found!
"