Question: When comparing strings with compareTo, the comparison is not always satisfactory. For example, file10.compareTo(file2) returns a negative value, indicating that file10 should come before file2,

When comparing strings with compareTo, the comparison is not always satisfactory. For example, "file10".compareTo("file2") returns a negative value, indicating that "file10" should come before "file2", even though we would prefer it to come afterwards. Produce a numCompare method that, when comparing two strings that are identical except for a positive integer at the end, compares the integers. For example, numCompare("file12", "file2") should return 1, but numCompare("file12", "file11") and numCompare("file2", "doc12") should return –1. Use a helper method that returns the starting position of the number, or –1 if there is none.

Step by Step Solution

3.47 Rating (176 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER public static int numCompareString s1 String s2 int s... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Concepts Late Objects Questions!