The Artima Developer Community
Sponsored Link

Java Answers Forum
can you help me find a recursive solution?

1 reply on 1 page. Most recent reply: Jan 17, 2008 3:12 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
reg delacosta

Posts: 1
Nickname: javarice
Registered: Jan, 2008

can you help me find a recursive solution? Posted: Jan 2, 2008 1:35 AM
Reply to this message Reply
Advertisement
i'm suppose to create a program that produces all possible combinations of a given morse code. I must use recursion in this problem.

example:
Enter morse code: --**--**
GAD GWI MIMI MIZ MUD ZMI ZZ
7 possible combination/s

I have already started.. please help me fill the question mark.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class cs12mp1{
public static String input(){
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
String input = " ";
System.out.print("Enter morse code message: ");
try{
input = dataIn.readLine();}
catch(IOException e){
System.out.println("Error!");}
return input;
}

public static void decode(String string, int size){
????????????????????????????????????????????????????????
}

public static void main(String args[]){
String string = input();
int size = string.length();
decode(string,size);
}
}


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: can you help me find a recursive solution? Posted: Jan 17, 2008 3:12 AM
Reply to this message Reply
Try to do it recursive.

For each letter you find on the beginning of the string (use startswith method), cal your method recursively again without the symbols used for that letter.

The return value of this method should be a vector of Strings.
combine the letter you found with all return strings of the recursive call.

Flat View: This topic has 1 reply on 1 page
Topic: can you help me find a recursive solution? Previous Topic   Next Topic Topic: Big help request

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use