gudii9
asked on
doubleChar java challenge
Hi,
I am working on below challenge
http://codingbat.com/prob/p165312
I tried my code as below
how to improve my approach, results and design of this challenge. How do i
make a graphical venn or flow chart or some other relevant diagram to design it
before writing code to decide best strategy?
Please advise
I am working on below challenge
http://codingbat.com/prob/p165312
I tried my code as below
public String doubleChar(String str) {
for(int i=0;i<str.length();i++){
char[] arrays=new char[]{str.substring(i, i+1);
}
//once get arrays get each character and add one more and make it string
}
how to improve my approach, results and design of this challenge. How do i
make a graphical venn or flow chart or some other relevant diagram to design it
before writing code to decide best strategy?
Please advise
Curiosity overwhelms me ... what is this homework for? Most technical questions are not phrased as a 'challenge' to 'improve my approach, results and design'.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
public String doubleChar(String str) {
StringBuilder sb=new StringBuilder();
String strNew=null;
int j=0;
for(int i=0;i<=str.length()-1;i++)
{
strNew=str.substring(j,j+1);
sb.append(strNew+strNew);
j++;
}
return sb.toString();
}
above passed all tests
ASKER
return str.replaceAll("(.)","$1$1");
what is meaning of above.
please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
for (char c : str.toCharArray()) {
is this new function from java 1.6 or later?
Nope it's not new - I think toCharArray() has been there since Java came along:
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toCharArray()
Doug
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#toCharArray()
Doug