0

No Numerals Problem Help

import java.util.*; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); String sc = input.nextLine(); String sc1 = sc.replaceAll("0", "zero").replaceAll("10", "ten").replaceAll("1", "one").replaceAll("2", "two").replaceAll("3", "three").replaceAll("4", "four").replaceAll("5", "five").replaceAll("6", "six").replaceAll("7", "seven").replaceAll("8", "eight").replaceAll("9", "nine"); System.out.println(sc1); } }

29th Mar 2022, 3:55 PM
Karl Davies
Karl Davies - avatar
4 Antworten
+ 2
Replace 10 before 0
29th Mar 2022, 3:59 PM
Simba
Simba - avatar
+ 2
Replacing every occurance in the whole line will give wrong results. "10 out of 1001 will fail"
29th Mar 2022, 5:23 PM
Brian
Brian - avatar
0
Does anbybody know why this code won’t work for the no numerals problem? There is only one test case that is not working
29th Mar 2022, 3:57 PM
Karl Davies
Karl Davies - avatar
0
Ah thank you Simba!
29th Mar 2022, 4:00 PM
Karl Davies
Karl Davies - avatar