+ 1
How did you write 0
You write a phrase and include a lot of number characters (0-9), but you decide that for numbers 10 and under you would rather write the word out instead. Can you go in and edit your phrase to write out the name of each number instead of using the numeral? Task: Take a phrase and replace any instances of an integer from 0-10 and replace it with the English word that corresponds to that integer. Input Format: A string of the phrase in its original form (lowercase). Output Format: A string of the updated phrase that has changed the numerals to words. Sample Input: i need 2 pumpkins and 3 apples Sample Output: i need two pumpkins and three apples
8 Answers
+ 6
Saidov Og'abek the reason why this code is not passing all the test cases is because it is not converting 10 to "ten". There is no problem with zero
+ 5
Share your attempt here.
And also 0 should be converted to "zero", you must be doing something wrong
+ 3
I don't get what you mean by "how do you write 0"?
0
1 => "one"
2 => "two"
...
...
0 => ?
0
I wrote 0 => "zero" but an error occurred
0
import java.util.HashMap;
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String text = scanner.nextLine();
HashMap<Integer, String> hashMap = new HashMap<>();
hashMap.put(0, "zero");
hashMap.put(1, "one");
hashMap.put(2, "two");
hashMap.put(3, "three");
hashMap.put(4, "four");
hashMap.put(5, "five");
hashMap.put(6, "six");
hashMap.put(7, "seven");
hashMap.put(8, "eight");
hashMap.put(9, "nine");
for (int i = 0; i < 10; i++) {
text = text.replace(String.valueOf(i), hashMap.get(i));
}
System.out.println(text);
}
}
0
This is my code but something wrong
0
Thank you Arsenic