Java program to print the output like- input will be "a4k3b2" and output should be after 'a' 4th character, after 'k' 3rd character and the final output : "aeknbd"




public class StringTest { public static void main(String[] args) { String str = "a4k3b2";// output aeknbd System.out.println(replaceChar(str));; } private static StringBuilder replaceChar(String str) { StringBuilder stB = new StringBuilder(); char[] c = str.toCharArray(); for (int i = 0; i < c.length; i++) { char cha = c[i]; if(Character.isAlphabetic(c[i])) { stB.append(cha); }else{ int v = c[i-1]; char value = c[i]; char digitChar = (char) (v + (value-48)); stB.append(digitChar); } } return stB; } }
Share:

No comments:

Post a Comment

Quote of the day

Popular Posts

Featured Post

Collection Framework Overview

Collection:- A collection (sometimes called a container) is simply an object that groups multiple elements into single unit. Collect...

Youtube Page

Facebook Page

Recent Posts

About

I am Shivaji Chandra and I'm a Computer Science Engineer. I love to write poems, jokes and quotes. click here →