In this Problem we learn how to replace a string with another string in Java. First we initialize an empty string and a string with sentence. Just use Java builtin function which receive two parameter of string. First String is the empty 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)); } }
Good :)
ReplyDelete