Results 1 to 18 of 18
  1. #1
    Nghasemi is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default StringManipulation

    I wrote this code and it doesn't work i have no idea why? i am new here:confused::(

    public class StringManipulation
    {
    public static void main(String[]args)
    {
    String sQuote = "Brian Loves NYC";
    String sQuote2 = new String("Brian Loves NYC");
    System.out.println(sQuote.substring(2));
    System.out.println(sQuote.substring(2, 5));
    System.out.println(sQuote.compareTo “Brian Loves nyc”);
    System.out.println(sQuote.length());
    System.out.println(sQuote.toUpperCase());
    System.out.println(sQuote.toLowerCase());
    System.out.println(sQuote.equals(sQuote2);
    System.out.println(sQuote.indexOf (“NYC”);
    System.out.println(sQuote.charAt(6));
    System.out.println(sQuote.indexOf “Dan”));
    System.out.println(sQuote.equals “Brian”);
    System.out.println(sQuote.replace('N','J'));

    System.exit(0);

    }


    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Nghasemi is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default

    What do you want me to do ?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Nghasemi View Post
    What do you want me to do ?
    Tell us what's wrong. What you expect to happen, what is happening, what's not happening. All you say is that it "doesn't work" and that tells us nothing useful at all, nothing that we can use to help you that is. Please read the link in my signature below asking smart questions and it will explain all this in detail as well as the information that we will need from you for your question to be answerable.

  5. #5
    Nghasemi is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default

    It doesn't compile the program and it tells me there are 18 error

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Nghasemi View Post
    It doesn't compile the program and it tells me there are 18 error
    OK, then please post the error message and let us know which line of code is causing it. Again, please read the "smart questions" link as this teasing information out of you will get old for both of us soon.

  7. #7
    Nghasemi is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default

    C:\Users\niloofar\Document\StringManipulation.java :18: illegal character: \8220
    System.out.println(sQuote.compareTo “Brian Loves nyc”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :18: ';' expected
    System.out.println(sQuote.compareTo “Brian Loves nyc”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :18: illegal character: \8221
    System.out.println(sQuote.compareTo “Brian Loves nyc”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :18: not a statement
    System.out.println(sQuote.compareTo “Brian Loves nyc”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :22: ')' expected
    System.out.println(sQuote.equals(sQuote2);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :23: illegal character: \8220
    System.out.println(sQuote.indexOf (“NYC”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :23: ')' expected
    System.out.println(sQuote.indexOf (“NYC”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :23: illegal character: \8221
    System.out.println(sQuote.indexOf (“NYC”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :23: illegal start of expression
    System.out.println(sQuote.indexOf (“NYC”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :25: illegal character: \8220
    System.out.println(sQuote.indexOf “Dan”) );
    ^
    C:\Users\niloofar\Document\StringManipulation.java :25: illegal character: \8221
    System.out.println(sQuote.indexOf “Dan”) );
    ^
    C:\Users\niloofar\Document\StringManipulation.java :25: not a statement
    System.out.println(sQuote.indexOf “Dan”) );
    ^
    C:\Users\niloofar\Document\StringManipulation.java :26: illegal character: \8220
    System.out.println(sQuote.equals “Brian”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :26: illegal character: \8221
    System.out.println(sQuote.equals “Brian”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :26: not a statement
    System.out.println(sQuote.equals “Brian”);
    ^
    C:\Users\niloofar\Document\StringManipulation.java :27: ')' expected
    System.out.println(sQuote.replace'N','J';
    ^
    C:\Users\niloofar\Document\StringManipulation.java :27: illegal start of expression
    System.out.println(sQuote.replace'N','J';
    ^
    C:\Users\niloofar\Document\StringManipulation.java :27: ';' expected
    System.out.println(sQuote.replace'N','J';
    ^
    18 errors

    Tool completed with exit code 1

  8. #8
    ramyashree is offline Member
    Join Date
    Feb 2011
    Posts
    1
    Rep Power
    0

    Default

    public class StringManipulation
    {

    /**
    * @param args
    */
    public static void main(String[] args)
    {
    String sQuote = "Brian Loves NYC";
    String sQuote2 = new String("Brian Loves NYC");
    System.out.println(sQuote.substring(2));
    System.out.println(sQuote.substring(2, 5));
    System.out.println(sQuote.compareTo("Brian Loves nyc"));
    System.out.println(sQuote.length());
    System.out.println(sQuote.toUpperCase());
    System.out.println(sQuote.toLowerCase());
    System.out.println(sQuote.equals(sQuote2));
    System.out.println(sQuote.indexOf("NYC"));
    System.out.println(sQuote.charAt(6));
    System.out.println(sQuote.indexOf("Dan"));
    System.out.println(sQuote.equals("Brian"));
    System.out.println(sQuote.replace('N','J'));
    System.exit(0);

    }
    }

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    Quote Originally Posted by Nghasemi View Post
    C:\Users\niloofar\Document\StringManipulation.java :18: illegal character: \8220
    Looks like you copied and pasted that code from somewhere and picked up some unwanted characters. Or you are using a non-standard text editor for your code, such as Word instead of notepad.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  11. #11
    Nghasemi is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Looks like you copied and pasted that code from somewhere and picked up some unwanted characters. Or you are using a non-standard text editor for your code, such as Word instead of notepad.
    Thanks alot

  12. #12
    Nghasemi is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default

    I am using TextPad that's what teacher told us to use

  13. #13
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Along with that, see how to use/complete brackets when we call methods and pass arguments.

    You can refer to the spoon-feeded / corrected code by Ramyashree.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  14. #14
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default

    TextPad should be OK so You must have copied the code from somewhere, perhaps a website. Where ever it says you have an illegal character just hit delete (and possibly reinsert CRLF)

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Or better, just type the code in yourself. Don't copy and paste at this point as you need to engage all parts of your brain when learning to code.

  16. #16
    Nghasemi is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default

    I had to copy one part of it from my teachers website because that was what he told us to do

  17. #17
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by Nghasemi View Post
    I had to copy one part of it from my teachers website because that was what he told us to do
    Considering your code length, why don't you simply type it manually on your own and see what happens?

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  18. #18
    Nghasemi is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •