Java is complaining about dead code in my translator:
public static void pigLatinify(String fname) throws IOException
{
File file = new File("projectdata.txt");
try
{
Scanner scan1 = new Scanner(file);
while (scan1.hasNextLine())
{
Scanner scan2 = new Scanner(scan1.nextLine());
while (scan2.hasNext())
{
String s = scan2.next();
boolean b = Syllable.countSyllables(s);
char firstLetter = s.charAt(0);
if (b = false && firstLetter=='a' || firstLetter=='i' || firstLetter=='o' || firstLetter=='e' ||
firstLetter=='u' || firstLetter=='A' || firstLetter=='I' || firstLetter=='O' ||
firstLetter=='E' || firstLetter=='U')
{
String output = s + "hay" + " ";
System.out.print(output);
}
else if (b = true && (firstLetter=='a' || firstLetter=='i' || firstLetter=='o' || firstLetter=='e' ||
firstLetter=='u' || firstLetter=='A' || firstLetter=='I' || firstLetter=='O' ||
firstLetter=='E' || firstLetter=='U'))
{
String output = s + "way" + " ";
System.out.print(output);
}
else
{
String restOfWord = s.substring(1);
String output = restOfWord + firstLetter + "ay" + " ";
System.out.print(output);
}
}
System.out.println("");
scan2.close();
}
scan1.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
The method called (Syllable.countSyllables) is:
class Syllable
{
public static boolean countSyllables(String word)
{
int vowelCount = 0;
word.toLowerCase();
for (int a = 0; a < word.length(); a++)
{
char test = word.charAt(a);
if (test == 'a' || test == 'e' || test == 'i' || test == 'o' || test == 'u')
vowelCount++;
}
if (vowelCount > 1)
return true;
return false;
}
}
Java says the result of local variable boolean b isn't being used. It also flags up the first "if" statement and says that the "firstLetter=='a' is dead code. It doesn't flag anything else up though.
Have I done something very silly I'm missing??
Thanks!