Solved

allStar challenge

Posted on 2016-09-21
1
57 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 52
Auto-indent certain lines in Notepad++ 10 75
login form jsp example 2 25
Which non-HTML GUI front end to use with Java? 3 22
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

773 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