[VIEWED 4838
TIMES]
|
SAVE! for ease of future access.
|
|
|
dhimaar1
Please log in to subscribe to dhimaar1's postings.
Posted on 02-20-08 6:50
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
hi. somebody plz help me with this java programming problem.
i have a string
String m = Nepal is beautiful.
So how do i replace all the characters with '*".
so that the output looks like this.
new string m1 = ***** ** *********
|
|
|
|
sangfroid
Please log in to subscribe to sangfroid's postings.
Posted on 02-20-08 7:49
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Here it comes... package replace; /** * */ import java.io.*; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { String mystring =" "; System.out.println("Enter the string"); BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) ); try { mystring = stdin.readLine(); } catch ( IOException e) { }; StringBuffer output =new StringBuffer(' ') ; for (int i=0;i<mystring.length();i++) { if (mystring.charAt(i)!=' ') output.append("*"); else output.append(" "); } System.out.println(output); } }
|
|
|
sangfroid
Please log in to subscribe to sangfroid's postings.
Posted on 02-20-08 7:51
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
there are however other ways to do it too...
|
|
|
dhimaar1
Please log in to subscribe to dhimaar1's postings.
Posted on 02-20-08 7:53
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
thanks for the help. but i am supposed to do it without using IO......... Is there a way to do it with only String class?? PLZ help me
Last edited: 20-Feb-08 07:58 AM
Last edited: 20-Feb-08 07:59 AM
|
|
|
sangfroid
Please log in to subscribe to sangfroid's postings.
Posted on 02-20-08 8:09
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
In that case, that is much more easier..just give a tweak to the code that i provided...
|
|
|
Echoes
Please log in to subscribe to Echoes's postings.
Posted on 02-20-08 8:53
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
String m = "Nepal is beautiful";
String m1 = m.replaceAll("\\w", "*");
|
|
|
dhimaar1
Please log in to subscribe to dhimaar1's postings.
Posted on 02-20-08 10:45
AM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
thanks a lot guys for your time and help...............
|
|
|
LondonBridge
Please log in to subscribe to LondonBridge's postings.
Posted on 02-20-08 3:06
PM
Reply
[Subscribe]
|
Login in to Rate this Post:
0
?
|
|
Here it goes: String a=" Nepal is beautiful"; String b=""; int n=a.length(); for(int i=0;i<n;i++){ if(Character.isWhitespace(a.charAt(i))){ b+=" "; } else{ b+="*"; } } System.out.println(b);
|
|