Ask Experts Questions for FREE Help !
Ask
    getvik_333's Avatar
    getvik_333 Posts: 5, Reputation: 1
    New Member
     
    #1

    Oct 19, 2014, 10:17 PM
    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".
    CravenMorhead's Avatar
    CravenMorhead Posts: 4,532, Reputation: 1065
    Adult Sexuality Expert
     
    #2

    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's Avatar
    getvik_333 Posts: 5, Reputation: 1
    New Member
     
    #3

    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's Avatar
    CravenMorhead Posts: 4,532, Reputation: 1065
    Adult Sexuality Expert
     
    #4

    Oct 20, 2014, 10:02 AM
    What is the assignment? The answer changes based on this.
    getvik_333's Avatar
    getvik_333 Posts: 5, Reputation: 1
    New Member
     
    #5

    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's Avatar
    CravenMorhead Posts: 4,532, Reputation: 1065
    Adult Sexuality Expert
     
    #6

    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's Avatar
    getvik_333 Posts: 5, Reputation: 1
    New Member
     
    #7

    Oct 20, 2014, 10:21 AM
    Thank you for your kind help that will definitely help me
    getvik_333's Avatar
    getvik_333 Posts: 5, Reputation: 1
    New Member
     
    #8

    Oct 25, 2014, 12:03 AM
    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

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Java string concatenation in the iteration [ 1 Answers ]

Hi everyone can any help me with this: Make a program that asks for an integer and prints all integers from one to the entered integer. By performing a string concatenation in the iteration, let the label text value to be the value it had last lap plus the new century. Thanks to everyone...

How to store Scanner data in string in java? [ 0 Answers ]

I am new to java, currently I am working on a program regarding networking. My program compiles without error. I have placed 3 checks in my program. It passes through check 1 but does not reach 2. I want string player2msg to store whatever data comes from scanner fromServer. I expected...

Having difficulty with Java String [ 1 Answers ]

Can someone please me how I can write a Java code to transform the quantity 6 As into the string AAAAAA. I'm trying this, but it does not work: public class Letters { public static void main (String args) { String words=" "; String numberofwords="A"; int wordcount=6;

Java netbeans program- Connection between java and mysql,How to conn [ 0 Answers ]

which I wrote from a book but when I run it, it shows exception please give me the code to connect jlistbox to database when I click on btn1. btn coding should search "name" in database and shows all the names in listbox my coding: here-- r1,r2,r3 are radio btns and l1,l2,l3 are labels,...


View more questions Search