The following is my code for a simple program I am doing. I'm not sure why the line containing .equalsIgnoreCase isn't working. Does anyone have any suggestions?
import javax.swing.*;
public class Assignment4
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(
null, "Greetings!"
String playerOne = JOptionPane.showInputDialog ("Player 1, please enter your name: "
String playerTwo = JOptionPane.showInputDialog ("Player 2, please enter your name: "
String word = JOptionPane.showInputDialog (playerOne + ", please enter a word: "
int stringLength = word.length();//Declaring variables
char lastChar = word.charAt(stringLength - 1);
JOptionPane.showInputDialog(playerTwo + ", please enter a word starting with letter " + lastChar + ":"
char firstChar = word.charAt(0);
if (lastChar.equalsIgnoreCase(firstChar)){
JOptionPane.showInputDialog(playerTwo + ", please enter a word starting with letter " + lastChar + ":"
}
else{
JOptionPane.showMessageDialog(
null, playerOne + "WON!"
}
JOptionPane.showMessageDialog(
null, "Click \"OK\" to end program."
String junk;
junk = SavitchIn.readLine();//Ending Program
System.exit(0);
}
}
import javax.swing.*;
public class Assignment4
{
public static void main(String[] args)
{
JOptionPane.showMessageDialog(
null, "Greetings!"
String playerOne = JOptionPane.showInputDialog ("Player 1, please enter your name: "
String playerTwo = JOptionPane.showInputDialog ("Player 2, please enter your name: "
String word = JOptionPane.showInputDialog (playerOne + ", please enter a word: "
int stringLength = word.length();//Declaring variables
char lastChar = word.charAt(stringLength - 1);
JOptionPane.showInputDialog(playerTwo + ", please enter a word starting with letter " + lastChar + ":"
char firstChar = word.charAt(0);
if (lastChar.equalsIgnoreCase(firstChar)){
JOptionPane.showInputDialog(playerTwo + ", please enter a word starting with letter " + lastChar + ":"
}
else{
JOptionPane.showMessageDialog(
null, playerOne + "WON!"
}
JOptionPane.showMessageDialog(
null, "Click \"OK\" to end program."
String junk;
junk = SavitchIn.readLine();//Ending Program
System.exit(0);
}
}