View Full Version : Java string program
getvik_333
Oct 19, 2014, 10:17 PM
Hii I please help me to make this string program I have to input "computer is fun" and output should be "is fun computer".
CravenMorhead
Oct 20, 2014, 07:29 AM
Look at String tokenization functions in the string library. What you can do with that is bust your string into tokens separated by a character, being white space in your case, and then you can do what you want with it. Is there a specific rule you have to use for this program?
getvik_333
Oct 20, 2014, 09:51 AM
Please help me in coding which string function we can use to manage these separate tokens in that order
CravenMorhead
Oct 20, 2014, 10:02 AM
What is the assignment? The answer changes based on this.
getvik_333
Oct 20, 2014, 10:05 AM
Thank you for your help but I'm looking for a program code for this explanation please help me in that I understand what you said but not able to convert it in program
CravenMorhead
Oct 20, 2014, 10:18 AM
The assignment specs tell me if you they want you to just juxtapose the first work last or if they want something more.
I am not going to post code. You have to write that yourself. There are several ways this could work, puesdo-code is:
// This will do what you want, but it will probably cause you to fail the assignment.
if( inputString == "Computer Is Fun")
systemPrint("Is Fun Computer");
//This could be a pass, but it isn't the most efficient way of doing it.
string firstWord;
string theRestOfIt;
bool haveFirstWord = false;
for(int I=0; I < inputString.Length; I++)
{
if(haveFirstWord)
theRestOfIt.append(inputString[i]);
else
firstWord.append(inputString[i]);
if(inputString[i] == ' ')
haveFirstWord = true;
}
systemPrint(theRestOfIt + firstWord);
// But wait, I googled the string class for Java.
string firstword = inputString;
firstword.replace(' ','\0'); // isolate the first word.
string theRestOfit = inputString.substring(firstword.length());
systemPrint(theRestOfIt + firstWord);
//------
Seriously, Google the Java string class, there is so much in there that can help you. It will all change if you need more versatility in your program as well.
getvik_333
Oct 20, 2014, 10:21 AM
Thank you for your kind help that will definitely help me
getvik_333
Oct 25, 2014, 12:03 AM
Thank you for your kind help that will definitely help me
I have tried above program and when I am compiling it I am getting an error "array riquired but java.string.lang found" please help me rectifying this error