Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

allStar challenge

Posted on 2016-09-21
1
Medium Priority
?
91 Views
Last Modified: 2016-09-22
Hi,

I am working on below challenge.
http://codingbat.com/prob/p183394
Psedo code:
1. check the array length 0  or 1 then retun same str
2.else return string with first character concatenated with * and then rest of characters argument recursion method

I wrote my code as below and passing all tests
public String allStar(String str) {
  if(str.length()==0||str.length()==1){
    return str;
  }
  else{
  return str.charAt(0)+"*"+allStar(str.substring(1));
  }
}

Open in new window


Any improvements or alternate approaches?      

please advise
0
Comment
Question by:gudii9
1 Comment
 
LVL 37

Accepted Solution

by:
zzynx earned 2000 total points
ID: 41810216
Not really.

public String allStar(String str) {
  if(str.length()<2){
    return str;
  }
  return str.charAt(0)+"*"+allStar(str.substring(1));
}

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question