Reversing a string in 3 ways using JavaScript

There are three popular ways you can reverse a string in JavaScript. Solution #1 - Using S-P-J (Split-Reverse-Join) Split the string into array of characters using split() function Reverse the characters of array using reverse() function Join back the characters in the array using join() function Solution #2 - Using Loop - C-L-A(Create - Loop … Continue reading Reversing a string in 3 ways using JavaScript

Advertisements

Dynamic String Conversion in JAVA

Input: 2B Output: 2000000000 Code : import java.math.BigDecimal; import java.util.Scanner; public class DyanamicConversion { public static void main(String args[]){ //Scanner scan = new Scanner(System.in); String a ="2M"; String[][] conversion = {{"K","1000"},{"M","1000000"},{"B","1000000000"}}; for(int i=0;i<conversion.length;i++){ if(a.endsWith(conversion[i][0])){ BigDecimal temp = new BigDecimal(a.substring(0, a.indexOf(conversion[i][0]))); temp.multiply(new BigDecimal(conversion[i][1])); a = temp.toBigInteger().toString(); System.out.println(a); break; } } } }