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); } }

19th Feb 2020, 4:35 PM
Anirvan Mandal
Anirvan Mandal - avatar
2 ответов
+ 6
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.
19th Feb 2020, 5:31 PM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 2
in actual code, delete } before println(s2) //} System.out.println(s2); } }
19th Feb 2020, 8:27 PM
zemiak