Help, no numerals | SoloLearn: Learn to code for FREE!

+1

# Help, no numerals

import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner (System.in); String s=sc.nextLine()+" "; String s1="",s2=""; String n="0123456789"; String t="10"; String no[]={"zero","one"," two","three","four","five","six","seven","eight","nine"}; for(int i=0;i<s.length();i++){ char ch=s.charAt(i); if(ch!=32){ s1=s1+ch; } else{ if(n.indexOf(s1)!=-1){ int n1=Integer.parseInt(s1); s2=s2+no[n1]+" "; } else if(s1.equals(t)){ s2=s2+"ten"+" "; } else{ s2=s2+s1+" "; } s1=""; } } } System.out.println(s2); } }

2/19/2020 4:35:21 PM

Anirvan Mandal

+4

It has very simple solution. Just replace every number with particular string by using replaceAll function. String str="123"; str=str. replaceAll("1","one").replaceAll("2","two").replaceAll("3","three"); System.out.println(str); //onetwothree Although you're code is not bad enough to pass this challenge but if you fail in something you have to change your hole idea rather than working into same code.Try differently for different difficulties.

+1

in actual code, delete } before println(s2) //} System.out.println(s2); } }