I was doing an exercise in my book and the exercise said, "Make a method that tests to see if the end of a string ends with 'ger.' Write the code to where it tests for any combination of upper-case and lower-case letters in the phrase 'ger.'"
So, basically, it asked me to test for a phrase within a string and ignore the case so it doesn't matter if letters in "ger" are upper or lower-case. Here is my solution:
package exercises;
import javax.swing.JOptionPane;
public class exercises
{
public static void main(String[] args)
{
String input, message = "enter a string. It will"
+ " be tested to see if it "
+ "ends with 'ger' at the end.";
input = JOptionPane.showInputDialog(message);
boolean yesNo = ends(input);
if(yesNo)
JOptionPane.showMessageDialog(null, "yes, \"ger\" is there");
else
JOptionPane.showMessageDialog(null, "\"ger\" is not there");
}
public static boolean ends(String str)
{
String input = str.toLowerCase();
if(input.endsWith("ger"))
return true;
else
return false;
}
}
as you can see from the code, I simply converted the string that a user would input to all lower-case. It would not matter if every letter was alternating between lower and upper-case because I negated that.