+ 2

No numerals without using replace()

Tried this code coach challenge without using replace() in java. Check it out !! Is it effective? https://code.sololearn.com/cvG03y4HuC3g/?ref=app

26th Jul 2020, 12:39 PM
kannan
kannan - avatar
7 Réponses
+ 1
Ya thanks. But the code that you have written above works only if that substring equals 10 (ie only 10 ex : i am 10) But for cases like this (ex : hello it is 2010) it won't work as 10 here is just a part of the substring
26th Jul 2020, 2:27 PM
kannan
kannan - avatar
+ 1
Ah no Jayakrishna🇮🇳 .. for 2010 it works fine it prints twozeroten you can check it out
26th Jul 2020, 2:40 PM
kannan
kannan - avatar
+ 1
No.kannan I mean for that problem, input have 0 to 10 numbers only.. It will not have >10. and if it contains, for ex:2010, then it shloud be two thousand and ten, not twooneten. I think, It will same result as you by my changes. Is it not? I will check ones.. If you find any, reply... Edit: The problem won't have input like 2010. So that's why I told. For all input according to problem description, it works fine..
26th Jul 2020, 2:49 PM
Jayakrishna 🇮🇳
+ 1
Ya thanks bro .. i got it. If inputs are less than or equals 10 then ur code is absolutely fine. But i thought there might be test cases greater than 10 and also in some cases numbers can be inside a substring like this Ex : i bought Hyundai i10 car last day here 10 resides in a substring ryt.. I thought of those and has handled them too. But for nums greater than ten it will work differently like if its i20 then it ll output itwozero Anyway thanks a lot for your time.!
26th Jul 2020, 2:55 PM
kannan
kannan - avatar
+ 1
Yes. I won't have and if it have like 20, also it sholud twenty not twozero.. That's need more calculations.. I have done that also.. You're welcome always..
26th Jul 2020, 3:00 PM
Jayakrishna 🇮🇳
0
I can't say it's effective or not. But to be effective, it is recommended to more readable and fast in execution with less code. For this problem, I would do changes from 2nd else to else if(ar[i].equals("10")){ ar[i]="ten"; } else{ ar[i]=ar[i]; } For this, code effective opinion type questions are should be posted in personal feed. Because every one approach is different.., until it it have performance effective methods.
26th Jul 2020, 1:15 PM
Jayakrishna 🇮🇳
0
Yes. I mentioned there as "for this problem ". (for 2nd else part only, 1st if unchanged) And For that 2010, you need more correction, your program also not work( as it prints twozeroonezero..). Since all simple calculation, try to be simple, easy understable. That's what I know.. And You're welcome..
26th Jul 2020, 2:35 PM
Jayakrishna 🇮🇳