+ 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

3rd Nov 2020, 6:57 AM
Saidov Og'abek
Saidov Og'abek - avatar
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
3rd Nov 2020, 7:38 AM
Arsenic
Arsenic - avatar
+ 5
Share your attempt here. And also 0 should be converted to "zero", you must be doing something wrong
3rd Nov 2020, 7:10 AM
Arsenic
Arsenic - avatar
+ 3
I don't get what you mean by "how do you write 0"?
3rd Nov 2020, 6:59 AM
Abhay
Abhay - avatar
0
1 => "one" 2 => "two" ... ... 0 => ?
3rd Nov 2020, 7:07 AM
Saidov Og'abek
Saidov Og'abek - avatar
0
I wrote 0 => "zero" but an error occurred
3rd Nov 2020, 7:08 AM
Saidov Og'abek
Saidov Og'abek - avatar
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); } }
3rd Nov 2020, 7:16 AM
Saidov Og'abek
Saidov Og'abek - avatar
0
This is my code but something wrong
3rd Nov 2020, 7:17 AM
Saidov Og'abek
Saidov Og'abek - avatar
0
Thank you Arsenic
3rd Nov 2020, 8:10 AM
Saidov Og'abek
Saidov Og'abek - avatar