Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Java string program (https://www.askmehelpdesk.com/showthread.php?t=803236)

  • Oct 19, 2014, 10:17 PM
    getvik_333
    Java string program
    Hii I please help me to make this string program I have to input "computer is fun" and output should be "is fun computer".
  • Oct 20, 2014, 07:29 AM
    CravenMorhead
    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?
  • Oct 20, 2014, 09:51 AM
    getvik_333
    Please help me in coding which string function we can use to manage these separate tokens in that order
  • Oct 20, 2014, 10:02 AM
    CravenMorhead
    What is the assignment? The answer changes based on this.
  • Oct 20, 2014, 10:05 AM
    getvik_333
    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
  • Oct 20, 2014, 10:18 AM
    CravenMorhead
    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.
  • Oct 20, 2014, 10:21 AM
    getvik_333
    Thank you for your kind help that will definitely help me
  • Oct 25, 2014, 12:03 AM
    getvik_333
    Error message
    Quote:

    Originally Posted by getvik_333 View Post
    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

  • All times are GMT -7. The time now is 10:40 AM.