Hi,
I want to take a
string such as "Hello" and convert that to a string that looks like this: "h + e + l + l + o" . This is the loop that I am using to try to accomplish this feat:
import javax.swing.*;
import java.text.*;
import java.util.StringTokenizer;
public class romanNumeral
//Naming the class and declaring it to be public
{//begin class
public static void main(String[] args)
{//begin method
String input = "hello";
StringTokenizer tokenizer = new StringTokenizer (input);
int stringLength = input.length();
String
word = " ";
String digit;
while (tokenizer.hasMoreTokens())
{//begin while
digit = tokenizer.nextToken();
if (stringLength == 1)
{//begin if
word = word + " " + digit;
}//end if
else
{//begin else
word = word + digit + " + " + stringLength;
}//end else
stringLength = stringLength - 1;
}//end while
JOptionPane.showMessageDialog(null,
"Your converted string is " + word,
"The Results",
JOptionPane.INFORMATION_MESSAGE);
}//end method
}//end class
This code returns "hello +".
I know that this is because the delimiter is not set right but I am not sure how to tell it to set each character as its own token as opposed to each word.
Please help!
Jason