Results 1 to 7 of 7
  1. #1
    madiya is offline Member
    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    Question Reassign new value to a variable

    Hi,
    I am new in the java world and just started learning.
    Here is my code.

    public class zz{

    public static void main(String args[]) {
    public string ss; <<<<<< This is error line
    String palindrome = "Dot saw I was Tod";
    int len = palindrome.length();
    System.out.println( "String Length is : " + len );
    System.out.println( palindrome );
    ss = palindrome;
    System.out.println( ss);
    }
    }

    It errors out while compiling at public string ss; saying illegal start of expression.
    Pl help.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,596
    Rep Power
    5

    Default Re: Reassign new value to a variable

    ss is a local variable in the main() method, it is not a class member. Only class members can have modifiers such as public, protected and private.

    So for every compile error you are going to ask a new question in a forum? I would rather buy a good book and study that, you'll save loads of time. I will predict that by the fifth trivial question you are going to ask, people are going to tell you to look stuff up yourself.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    madiya is offline Member
    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    Default Re: Reassign new value to a variable

    Thanks for the quick reply.
    I have removed the modifier and change the assignment as below.
    string ss = palindrome;
    But still getting error that cannot find symbol.
    Pl help.
    I am trying to learn the java with a online tutorial at Java Tutorial
    I am trying to modify the given code there to see if I understand properly or not.

    Pl help.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,596
    Rep Power
    5

    Default Re: Reassign new value to a variable

    Get a good book; tutorials tend to be written for people who have a programming history and so can fill in the huge gaping blanks that are in the tutorial.

    Repost your new code. I am guessing that you are trying to assign the palindrome variable to the ss variable before it even exists, but I am not psychic.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    madiya is offline Member
    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    Default Re: Reassign new value to a variable

    Thanks.
    Here is my new code.
    public class zz{

    public static void main(String args[]) {

    String palindrome = "Dot saw I was Tod";
    int len = palindrome.length();
    System.out.println( "String Length is : " + len );
    System.out.println( palindrome );
    string ss = palindrome; <<<<<< This is error line
    System.out.println( ss);
    }
    }

    On error line compiler says cannot find symbol.

    Pl help.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,596
    Rep Power
    5

    Default Re: Reassign new value to a variable

    I'm not going to answer this, you clearly spent no time at all trying to figure out what is wrong. Take a look at your code, the mistake is incredibly easy to spot.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    902
    Rep Power
    2

    Default Re: Reassign new value to a variable

    Hint: Java is case-sensitive...

Similar Threads

  1. Replies: 2
    Last Post: 01-09-2013, 08:10 PM
  2. How to compare variable with multiple variable?
    By mharckz009 in forum New To Java
    Replies: 5
    Last Post: 09-11-2012, 04:33 PM
  3. Replies: 1
    Last Post: 04-21-2012, 06:03 PM
  4. Dynamic variable name based on other variable
    By nadissen in forum Eclipse
    Replies: 4
    Last Post: 05-06-2011, 06:22 PM
  5. Replies: 11
    Last Post: 07-07-2010, 06:02 AM

Tags for this Thread

Posting Permissions

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