Solved

allStar challenge

Posted on 2016-09-21
1
40 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 500 total points
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A short article about problems I had with the new location API and permissions in Marshmallow
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now