Structure of the Problem Requirements
In this Problem we learn how to replace a string with another string in Java. First we initialize am empty string and a string with sentence with replace the first string which we receive from user . Just use Java builtin function which receive two parameter of string . First String is the actual string and the Second string is that which is replaced.
Source Code
package com.ancodingpoint.ww;
import java.util.Scanner;
public class String_Replacement {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
String sentence = "";
String b = " This is the Second string which replace the first one! ";
System.out.println(" Enter Your Story ...");
sentence = input.nextLine();
System.out.println(sentence.replaceAll(sentence, b));
}
}
Output of the Program
Java String Programming |
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
Good :)
ReplyDelete