PROGRAM TO FIND A CHARACTER & REPLACE WITH A CHARACTER IN A GIVEN STRING(JAVA)

 Replace.java

package replace;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Scanner;

public class Replace {

public static void main(String[] args)throws StringIndexOutOfBoundsException, IOException {

        String given,changed;

        char f,r; 

        Scanner reader = new Scanner(System.in);             

        BufferedReader br = new BufferedReader ( new InputStreamReader(System.in));

        System.out.println("Enter any String");

        given=br.readLine();                

        System.out.println("Give any  character to Find in the String");

        f = reader.next().charAt(0);                

        System.out.println("Give any  character to Replace in the String");

        r = reader.next().charAt(0);                

        System.out.println("Given String is ="+ given);        

        int Len=given.length();

        System.out.println("Length of the Given String is ="+ Len);        

       changed = given.replace(f, r);

        System.out.println("String after Replacement of "+r+"  character is =" +changed);

    }    

}



OUTPUT:



No comments:

Post a Comment