Need easy method | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2

Need easy method

Is there any way method to solve this code with java

8th Oct 2022, 2:15 PM
Shivam Shiva
Shivam Shiva - avatar
2 Réponses
+ 4
Your code is working fine, it does what the task requires. A couple of remarks: - generally, adding a lot of strings is very inefficient, you should use a StringBuilder - in the top branches of 'if' where you check the type of character, you always have a special case, like letter 'A'. You could simplify this inner part by using ternary expressions: (condition ? when_true : when_false) - in my opinion the cleanest way would be to define a HashMap from each source character to target mapping, which already covers the special cases. If the mapped character is not found in the hashmap, then the default ~ char would be used. I just can't resist adding, that if you are looking for an EASY method, then you should do this in Kotlin instead. there are lots of convenient collection methods there which make this look very complicated to do in Java.
8th Oct 2022, 2:56 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Just for comparison, I did this in Kotlin with the hashmap idea.
8th Oct 2022, 3:29 PM
Tibor Santa
Tibor Santa - avatar