Nishant Jain
not sucess
0 Answer(s)      4 years and 3 months ago
Posted in : Java Beginners

import*; public class Replace{ public static void main(String[]args) throws IOException { InputStreamReader z= new InputStreamReader(; BufferedReader br=new BufferedReader(z); System.out.println("Enter A String:"); String s=br.readLine(); System.out.println("Enter First Word:"); String w1=br.readLine(); System.out.println("Enter Second Word:"); String w2=br.readLine(); String rep=s.replace(w1,w2); System.out.println("Replaced String: "+rep); } }

Respected sir, extremely thanks to you for give me answer of my question but sir above code has a one problem when i'm input this string "This is a flower" and first word is "is" or second word is "was" then output is "Thwaswas a flower" and i want output like this e.g input string "This is a flower" first word "is " second word "was" then output will be print like this "This was a flower" not like this "Thwaswas a flower"

output after compiling your code

Enter A String: THIS IS A FLOWER Enter First Word: IS Enter Second Word: WAS Replaced String: THWASWASA FLOWER

View Answers

Related Tutorials/Questions & Answers:
Java String Split Example
args[]) { //Defining string and array String sample = "Sucess-need... OF SPLITTING STRING Splitting string at '-' Sucess need continous effort Splitting string at '.' Sucess
keeping log of page load - Java Beginners
log for sucess and failure both for page loading. Can you please give me some
java auto mail send - Struts
_to = "", m_subject = "Hi Testing Sucess", m_text = "Hey Nallavane...,Sucess this is the testing email from our Tool
){ System.out.println("sucess entering StaffingDAO"); Session... createUsers(Users users){ System.out.println("sucess entering UsersDAO
testcases - JUNIT
"POST_FAILURE"; } else return "POST_SUCESS...) return "POST_FAILURE"; else return "POST_SUCESS
Arrays, loops and string handling
array. after successful capture of the marks, show another sucess confrimation
SQLGrammarException while trying to save data in db
mapping.findForward("sucess"); } catch (Exception e...="sucess" path="/sucess.jsp"/> <forward name="failure" path
Servlet Error Message based on user input
the sucess message otherwise it displays the error message. So, you can use Servlet
Login form in Struts2 version 2.3.16
; <p>Enter User name: Admin and Password: Admin for checking the login sucess
Java : Servlet Tutorials
. If the entered name exists in the database its displays the sucess message otherwise