15
Your RegEx expression is slightly off. Try this:
System.out.println("I end with a number 4".matches("^.*\\d$"));
You can also simply test like this if you are evaluating a line at a time:
System.out.println("I end with a number 4".matches(".*\\d"));
Your original expression, without .* only tested to see whether the string was a number and did not account for text that may precede that number. That's why it was always false.
The following does evaluate to true:
System.out.println("4".matches("^\\d$"));
System.out.println("I end with a number 4".matches(".*\\d")); // prints true
or
String s = "I end with a number 4";
System.out.println(Character.isDigit(s.charAt(s.length()-1))); // prints true