Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.equalsIgnoreCase 1

Status
Not open for further replies.

jeak

Technical User
Oct 9, 2002
16
US
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);
}
}
 
That does not work because firstChar and lastChar are not Strings, they're chars. If you need to use that method try your conditional statement like this:

if( ( "" + lastChar ).equalsIgnoreCase( ( "" + firstChar ) ) )

-gc "I don't look busy because I did it right the first time."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top