java problem

Discussion in 'Computer Science & Culture' started by SonOfBOB, Sep 13, 2003.

Thread Status:
Not open for further replies.
  1. SonOfBOB Registered Member

    Messages:
    11
    ok problem and not sure why

    the code:

    String firstWord =
    originalWordSet.substring(0,originalWordSet.indexof(0,ch));

    problem:

    can not resolve symbol
    ...originalWordSet.substring(...
    . . . . . . . . . . . . . . ^


    please help no clue what this means
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. coolmacguy Registered Senior Member

    Messages:
    158
    It looks as if it's not recognizing originalWordSet as a string. Maybe you should post your code for that.
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. SonOfBOB Registered Member

    Messages:
    11
    ok the code for originalWordSet is:

    String originalWordSet =
    JOptionPane.showInputDialog("Enter 4 words seperated by a *");
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. piirx Registered Member

    Messages:
    24
    Make sure that you've declared originalWordSet before firstWord. Otherwise your code looks fine to me.

    ~piirx
     
  8. SonOfBOB Registered Member

    Messages:
    11
    it is but I am still geting the error
     
  9. CamThompson Registered Member

    Messages:
    5
    It might not even be that thats the problem. If you are missing a brace of some kind it could begiving you that error, is that your only error? maybe you should post your entire code.
     
  10. SonOfBOB Registered Member

    Messages:
    11
    my code

    import javax.swing.JOptionPane;

    class WORDS{
    public static void main(String args[])
    {
    String originalWordSetstr =
    JOptionPane.showInputDialog("Enter four(4) words seperated by a *");
    String originalWordSet = originalWordSetstr;
    String firstWord = originalWordSet.substring(0,originalWordSet.indexOf(0,'*'));
    String secondWord = originalWordSet.substring((originalWordSet.indexOf(0,'*')+1), originalWordSet.indexOf((originalWordSet.indexOf(0,'*')),'*'));
    String thirdWord = originalWordSet.substring((originalWordSet.indexOf((originalWordSet.indexOf(0,'*')),'*')+1),originalWordSet.indexOf(originalWordSet.indexOf(originalWordSet.indexOf(0,'*'),'*'),'*'));
    String forthWord = originalWordSet.substring((originalWordSet.indexOf(originalWordSet.indexOf(originalWordSet.indexOf(0,'*'),'*'),'*')+1),(originalWordSet.length()+1));
    String newWordSet = forthWord + "*" + thirdWord + "*" + secondWord + "*" + firstWord;
    String message = "your string: " + originalWordSet + "/n The new word order: "+newWordSet;
    JOptionPane.showMessageDialog(null,message);
    System.exit(0);
    }
    }
    ok I found and fixed my error but it still not doing what it suposed to
     
  11. okinrus Registered Senior Member

    Messages:
    2,669
    You have the indexOf parameters reversed.
    It's easiest to do this problem using a StringBuffer an a array of words. For example, you could write something that looks like this

    Code:
    ...
    // s is what we are parsing
    while(i < s.length()) {
        int c; 
        StringBuffer sb = new StringBuffer();
        
        // continue adding to our token until we hit the delim '*' or
        // at we are at the end of the string
        while((c = s.charAt(i)) != '*' && i < s.length()) {
            sb.append(c);
            i++;
        }
        word[i] = sb.toString();
        i++;                                // skip over the the '*'
    }
    
     
Thread Status:
Not open for further replies.

Share This Page