0

Can't work why?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String letter=sc.nextLine(); String[]num={"0","1","2","3","4","5","6","7","8","9"}; String[]word={"zero","one","two","three","four","five","six","seven","eight","nine"}; for(int i=0;i<=num.length-1;i++){ String letter1=letter.replaceAll(num[i],word[i]);} System.out.println(letter1); } }

2nd Dec 2021, 4:28 AM
Killiam Chances
Killiam Chances - avatar
2 Answers
+ 2
'letter1' doesn't exist outside the for-loop. Also, you should assign to 'letter1' from the already modified string (letter1) , not the source (letter) String letter1 = letter; for(int i=0; i<n.length; i++){ letter1 = letter1.replace... }
2nd Dec 2021, 5:23 AM
Angelo
Angelo - avatar
0
thank you
2nd Dec 2021, 2:04 PM
Killiam Chances
Killiam Chances - avatar