2021年4月2日星期五

Compare two strings (numbers as word)

I have been given numbers as words {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};(numbers are only up-to 10) and I my task is to compare given two input strings to each other.

It should basically work as you compare two numbers:

compare(1, 1) -> 0;  compare(1, 3) -> 1 < 3 as -1;  compare(5, 2) -> 5 > 2 as 1;  

What would be the best suitable way to compare two strings like this?

Result would look something like this:

compare("one", "one") -> 0;  compare("one", "three") -> -1;  compare("five", "two") -> 1;  
public int compare(String a, String b) {          return 0;      }  
https://stackoverflow.com/questions/66857504/compare-two-strings-numbers-as-word March 29, 2021 at 11:59PM

没有评论:

发表评论