Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do you code this in Java? Problem 2: When comparing strings with the built-in method compareTo, the comparison is not always satisfactory. For example,

How do you code this in Java?

image text in transcribed

Problem 2: When comparing strings with the built-in method 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 method int numCompare(String str1, String str2) 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. Write and use a helper method int findNumberPosition (String str) that returns the starting position of the number, or 1 if there is none

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: KROENKE DAVID M.

1st Edition

8120322258, 978-8120322257

More Books

Students also viewed these Databases questions

Question

Identify the types of informal reports.

Answered: 1 week ago

Question

Write messages that are used for the various stages of collection.

Answered: 1 week ago