I need it to check if a guessed letter is in the word and if it is to show it. I really need someone different to take a look at this and give me some ideas on where to go. All the code is starting to blur together on me. This is what I have so far:
import java.util.*;
import java.io.*;
import java.lang.*;
public class testIt
{
public static void main(String[] args) throws Exception
{
String word = Word();
String dashes = "------------------------------------------";
String wordDashes=dashes.substring(0, word.length());
int count = 0;
StringBuffer sb = new StringBuffer(word);
char[] chArr = new char[word.length()];
sb.getChars(0, word.length(), chArr, 0);
System.out.println(sb);
System.out.println(wordDashes);
do
{
char x = word.charAt(count);
char y = getChar();
String s = Character.toString(x);
String k = Character.toString(y);
boolean n = s.equalsIgnoreCase(k);
if (n){
System.out.println("YAY! They match!");}
else if (!n) {System.out.println("Try Again");}
}
while (count != word.length());
}
static char getChar()
{
Scanner s = new Scanner(System.in);
return s.next().toLowerCase().charAt(0);
}
static String Word() throws Exception
{
Scanner s = new Scanner(new FileReader("dictionary.txt"));
String[] words = new String[10];
for (int i=0; i< words.length; i++)
words[i] = s.nextLine();
int Index = (int)(Math.random() *words.length);
String secretWord = words[Index];
return secretWord;
}
}
This post has been edited by Toral: 02 May 2009 - 01:54 PM

New Topic/Question
Reply



MultiQuote




|