I want to replace the occurrences of a character by another character but getting an error, not likely an error..the code runs but doesn't take input for second character to be inputted.

I want to replace the occurrences of a character by another character but getting an error, not likely an error..the code runs but doesn't take input for second character to be inputted.

import java.io.*;

class replacement

{

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

{

DataInputStream in=new DataInputStream(System.in);

String str=new String();

String str1=new String();

System.out.print("Enter a Text:");

str=in.readLine();

System.out.print("Enter the Character which you want to be Replace:");

a=(char)System.in.read();

System.out.print("Enter the character to be replaced:");

d=(char)System.in.read();

System.out.print("\nYour Text:"+str);

str.replace('a','d');

str1=str;

System.out.print("\nAfter Replacement:"+str1);

}

}

View Answers

July 6, 2012 at 8:47 PM

This is the output which i get.

Enter a Text:i am learning java

Enter the Character which you want to be Replace:a

Enter the character to be replaced:

Your Text:i am learning java

After Replacement:i am learning java


July 6, 2012 at 8:50 PM

Sorry,i forgot to write char during declaration of variables when writing this post.









Related Tutorials/Questions & Answers:
illeagal character error....
illeagal character error....   Here is my code: import java.io....); } } error: MainScreen.java:19: illegal character: \96 ` Container container
replace character in php
replace character in php  PHP script that replace character
Advertisements
Replace Character in String
Replace Character in String      ... in a given string. To replace a character with the given character in sting first... name for replace) to be change with the new character of the array. If any match
Java I/O Character Streams
that facilitate to take input (read) the character stream. Subclasses...Java I/O Character Streams In this section we will discuss the I/O Character... and for this Java provides the Character stream I/O. Character stream I/O
How to get the unicode of japanese character input in java
How to get the unicode of japanese character input in java  Good Evening sir/madam; I am trying to create an application in java which needs to show the japanese character on frame and need to get the japanese string from
How to convert entity character to html character
How to convert entity character to html character  Please help me to "convert entity character to html character" in java. If possible please provide source code which take String as input and return as String
How to get the unicode of chinese character input in j2me/java
How to get the unicode of chinese character input in j2me/java  Hi All, How to get the Unicode of a chinese character either in j2me or Java? Please provide the sample code snippet for the above ? Thanks in advance... Thanks
Character class
Character class   Character defines the forDigit();,digit()methods..how can these b used and wht does radix point signify here.i want to knw what basically radix is??here in the arguments of these two???because i tried runnin
underscore as character
underscore as character  how can i consider _ as a character instead of wildcard character? my problem is like this i have 20 records as follows manohar 1234455 manohar 453635 manohar 345454 manohar_1234455 now when i am
Character Class
Character Class  Character defines the forDigit();,digit()methods..how can these b used and wht is radix point signifies here...in the arguments of these two???..pls answer a code on this with radix .. are these methods also
How to convert entity character to html character
How to convert entity character to html character  How to convert entity character to html character
find the first character is vowel or not
find the first character is vowel or not  hi friend, can u plz send me javascript code for find the wether the first character is a vowel or not. 2) check wether the last character is same as the first character or not 3) check
Unknown Character set: 'utf8mb4'.
Unknown Character set: 'utf8mb4'.  While working on eclipse on an application that uses MySQL as the back end for the database, I was having error connecting with the database through JDBC, when i try to run the application
Removing character from a string in sql.
Removing character from a string in sql.  How to remove or replace character from a string
J2ME count character into string
J2ME count character into string  i am new in J2ME, my problem is how to count character into number, i had been research google for almost 2 days... form which allow user to input character user input helloworld then press
php remove last character
php remove last character  to remove the last character, i used the trim function which is not working
Determining the type of Character
determines if the specified character is a Unicode space character. Here is the code...Determining the type of Character In this section, you will learn how to determine the type of a character. You can use the methods of Character class
JavaScript regex validate Character
character value : <input type="text" name="name" id="name" /> <input type... Character.   <html> <head> <title>Character validation... Character value : "+name); return true; } alert
JavaScript regex validate Character
character value : <input type="text" name="name" id="name" /> <input type... Character   <html> <head> <title>Character validation... Character value : "+name); return true; } alert
Java get middle character
Java get middle character In this tutorial, you will learn how to get middle character from the word. Here is an example of getting the middle letter...' and you want to get the character 'p' from the word, then you can
character literal in octal format
;>> EscapeSequence1.java:6: error: unclosed character literal char... ^ EscapeSequence1.java:6: error: unclosed character literal char ch2...character literal in octal format  class EscapeSequence1 { public
How to sort chinese character in j2me?
How to sort chinese character in j2me?  Hi All, I want to sort chinese character in j2me. Please let me know whether it is achievable or not in j2me? If Yes,Please help me by providing some sample code snuippet for sorting
Character Wrapper Class.
Character Wrapper Class.  what are Mirrored Unicode Characters?? and whats the use of "isMirrored(ch);method ??.where ch is any character argument.... There are special characters in UNICODE to achieve the RTL. Such character is the Mirroring
character as command line arguments
character as command line arguments  public class testing { public static void main(String args[]) { char a; a=args[0]; System.out.println("character is:"+a); } } what will be the above program output
Wrapper Character class.
character. A character is considered to be an ISO control character if its code...Wrapper Character class.  How do the methods 'isIndentifierIgnorable(ch)' and 'isISOControl(ch)' work?? while workin with 'Character' wrapper class
password validation with special character
password validation with special character  how to validate password with special character using java script
How to display string or character
How to display string or character  how to print character or a word without using array concept
Alphabet Character Case-Converter
converted lowercase character.  Here is the code of this program... Alphabet Character Case-Converter   ... a character (uppercase) into a lowercase character. The java.lang package provides
Adding slash "\" character before quote "'" in a query
Adding slash "\" character before quote "'"...; Adding slash "\" character before quote "'"... the phrases like "What's your name?", database gives the error due
What is Character Functions
What is Character Functions  What is Character Functions   Hi, Here is the answer,ADS_TO_REPLACE_1 Character Functions are INITCAP, UPPER, LOWER, SUBSTR & LENGTH. Additional functions are GREATEST & LEAST
Character Directions in java
Character Directions in java  java 2,version 1.4 adds a method "getDirectionality();" , what is the use of this method ?   This method returns the Unicode directionality property for the given character. Character
Count the character in java
Count the character in java  Write a java program to count the character ââ?¬Ë?aââ?¬â?¢ typed by the user in a paragraph by implementing thread...(String[] args) throws Exception{ Scanner input=new Scanner(System.in
Character count by while loop
Character count by while loop  Write the program to count the number...]; int count=0; for ( int i=0; i<third.length; i++){ if (ch==third[i...]) flag=true; } if(!flag){ System.out.println("Character :"+ch+" occurs "+count
character counter - Java Beginners
character counter  how to show only first three characters...!!"); } else{ System.out.println("First Three Character is:"+c[0]+c[1]+c[2... void main(String args[]) { new counter(); } } this code
count the repeated character in one string
count the repeated character in one string  to find the how character... 'a 'was repeated )   Hi Friend, Try the following code: import... Exception{ Scanner input=new Scanner(System.in); System.out.print("Please
Prinnt UNICODE character on swing component
Prinnt UNICODE character on swing component  Hello, I am trying to put unicode character n swing component. can anyone tell me how to do this? Thank you
i am unable to identify the error in my code
i am unable to identify the error in my code  class Program... a character"); char ch=(char)br.read(); System.out.println("the entered character is:"+ch
i am unable to identify the error in my code
i am unable to identify the error in my code  class Program... a character"); char ch=(char)br.read(); System.out.println("the entered character is:"+ch
Find out last character of array
Find out last character of array  How we can find out the last character of array in java program
Setting the default Java character encoding?
Setting the default Java character encoding?  Setting the default Java character encoding
Character encoding problem with chinese language
Character encoding problem with chinese language  I have a issue with characters in chinese locale in java. Iam using eclipse IDE My code...(stdDate);" But iam getting month name as '??' Can anyone help me to solve
Get Character
Get Character       In this example given below, we will learn how to read character from keyboard and display on standard output device. Method System.in.read() read character
Convert Character into Integer
the character data into an integer type. Description of code:ADS_TO_REPLACE_1... Convert Character into Integer       In this section, you will learn to convert the character
word and character counting - Java Beginners
word and character counting  here is the java code i made but i have to add something where it will read the inFile and display the number of words...) { JOptionPane.showMessageDialog(null, "Error:" + x1); System.exit(0
Regular expression contains character - PHP
Regular expression contains character  A PHP script that can check if the regular expression contains character
Removing character from a string in sql.
Removing character from a string in sql.  Removing special characters from a string in sql
getting error in your login form code
getting error in your login form code  i tried your code for login form but i am getting an error.the error is undefined index userid and password.the code is $fuser=$POST["userid"];. how to solve this problem please help me
Get Character from String
Get Character from String     ... of character and retrieve elements from that character array one by one. Description of the code: 1. First declare and initialize string. 2. use method
javascript regex validate Special character
> Enter Zip Code : <input type="text" name="zip" id="zip" /> <input...javascript regex validate Special character   javascript regex validate Special character   <html> <head> <title>Zip
Check character in upper case or not.
Description: This tutorial demonstrate the use of Character.isUpperCase() method for rectifying whether the value stored in char is in uppercase or not. Code: public class CheckUpper {  

Ads