Results 1 to 10 of 10
  1. #1
    antgaudi's Avatar
    antgaudi is offline Member
    Join Date
    Sep 2008
    Location
    Houston-TX
    Posts
    22
    Rep Power
    0

    Default Error: LengthCharAt.java:3: ';' expected public static void main (String[] args)

    I keep getting this error for the code below:
    LengthCharAt.java:3: ';' expected public static void main (String[] args)

    What am I doing wrong?
    Thanks.

    public class LengthCharAt
    {
    public static void main (String[] args)
    private static void StringMethod()
    {
    String stringVariable = new String("helo");
    String[ ] stringArray = {"abcd", "f", "wxy", "kl"};
    stringVariable=stringVariable.charAt
    (stringArray[3].length()) + stringVariable;
    System.out.println(stringVariable);
    }
    }
    "The minute you settle for less than you deserve, you get even less than you settled for." Maureen Dowd

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    You cannot declare one method in another,as you did.

  3. #3
    antgaudi's Avatar
    antgaudi is offline Member
    Join Date
    Sep 2008
    Location
    Houston-TX
    Posts
    22
    Rep Power
    0

    Default

    so how could this code work? thanks.
    "The minute you settle for less than you deserve, you get even less than you settled for." Maureen Dowd

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Java Code:
    public class LengthCharAt
    {
        public static void StringMethod()
        { 
             String stringVariable = new String("helo");
             String[ ] stringArray = {"abcd", "f", "wxy", "kl"};
             stringVariable=stringVariable.charAt(stringArray[3].length())+stringVariable;
             System.out.println(stringVariable);
         }
         public static void main (String[] args)
        {
               new LengthChartAt().StringMethod();
        }
    }

  5. #5
    antgaudi's Avatar
    antgaudi is offline Member
    Join Date
    Sep 2008
    Location
    Houston-TX
    Posts
    22
    Rep Power
    0

    Default

    I keep getting error for line 12: java:12: cannot find symbol
    symbol : class LengthChartAt
    location: class LengthCharAt
    new LengthChartAt().StringMethod();

    dunno... :(
    "The minute you settle for less than you deserve, you get even less than you settled for." Maureen Dowd

  6. #6
    antgaudi's Avatar
    antgaudi is offline Member
    Join Date
    Sep 2008
    Location
    Houston-TX
    Posts
    22
    Rep Power
    0

    Default

    are you a java tutor or do you know any?
    "The minute you settle for less than you deserve, you get even less than you settled for." Maureen Dowd

  7. #7
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    there is an error,remove letter "t",the name of the class was pselled wrong

    Java Code:
    new LengthCharAt().StringMethod();

  8. #8
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Quote Originally Posted by antgaudi View Post
    are you a java tutor or do you know any?
    What kind of question is that?What did you mean by that?

  9. #9
    antgaudi's Avatar
    antgaudi is offline Member
    Join Date
    Sep 2008
    Location
    Houston-TX
    Posts
    22
    Rep Power
    0

    Default

    if you teach java because I need help to pass an exam at the university. :)
    "The minute you settle for less than you deserve, you get even less than you settled for." Maureen Dowd

  10. #10
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    I work in this area.If you want to ask some specific questions,you can write a private message.
    Last edited by serjant; 11-23-2008 at 12:06 AM.

Similar Threads

  1. Why can't we write main without String args[]
    By shailender in forum New To Java
    Replies: 6
    Last Post: 06-17-2013, 10:28 AM
  2. Replies: 5
    Last Post: 10-06-2008, 01:11 AM
  3. calling a public void method from a class button
    By supa_kali_frajilistik in forum AWT / Swing
    Replies: 4
    Last Post: 05-23-2008, 02:05 PM
  4. Replies: 5
    Last Post: 01-25-2008, 12:53 AM

Posting Permissions

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