Topics Index

Prefix every character in the input string

If you need explanation Read this topic

If you need Answer Take test on this topic

Given the word as a String, then write a program to prefix every character in the input string.

Input (String, char) Output (String)
Prabhas, K KPKrKaKbKhKaKs
Dhoni, E EDEhEoEnEi
Mother, O OMOoOtOhOeOr
Book, M MBMoMoMk
Welcome, R RWReRlRcRoRmRe

class PrefixEveryCharacterInString
    public static void main(String s[])
        System.out.println("After prefixing : " + prefixEveryCharacter("Prabhas", 'K'));


    public static String prefixEveryCharacter(String word, char prefix) {

Topic: charAt() Method In Java - Java Character Extraction

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

As per the question we need to prefix the input string with given character and store it in a output string and should return it... so first take a output string and process for loop which helps us to get a single character from the string and iterate it until the end of string... Add the character which is to be prefixed and then add the character retrieved from the string... (i.e., result += prefix + word.charAt(i)) this statement helps you to prefix every character of the given word and then return it...

Posted by Gopinath Manchikanti    2015-02-18 07:42:10

here we have to prefix the input string with a character given as in example..... so for this traverse every character of string and prefix tht char in input.... firstly... output=char....den takea loop.... a=0 to input.length.... output=input.charAt(a) + (plus)char.... end loop aftrr this we wil get the required output

Posted by Asma Mujtaba Khan    2015-02-18 11:56:33

This dose is now closed and the winners are Gopinath Manchikanti,  for 'First Correct Comment', Asma Mujtaba Khan,  for 'Second Correct Comment'. The 'lucky liker' is Bolo Rarkings. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2015-02-19 04:44:37

© meritcampus 2019

All Rights Reserved.

Open In App