syntax error? "cannot find symbol"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bjorn Jensen

    syntax error? "cannot find symbol"

    Hi!
    An beginner question:
    Pleas help me with this (-:

    Error (the arrow points on the s in sqrt)
    =====
    tal.java:6: cannot find symbol
    symbol : method sqrt(int)
    location: class tal
    System.out.prin tln(i + ": " + sqrt(4));
    ^
    1 error


    Source
    =====
    class tal {
    public static void main(String[] arguments) {
    for (int i=0; i<11; i++) {
    System.out.prin tln(i + ": " + sqrt(4));
    }
    }
    }

    /Bjorn


  • cp

    #2
    Re: syntax error? &quot;cannot find symbol&quot;


    "Bjorn Jensen" <b.d.jensenremv oe@gmx.netwrote in message
    news:44c361de$0 $3482$ba624c82@ nntp02.dk.telia .net...
    Hi!
    An beginner question:
    Pleas help me with this (-:
    >
    Error (the arrow points on the s in sqrt)
    =====
    tal.java:6: cannot find symbol
    symbol : method sqrt(int)
    location: class tal
    System.out.prin tln(i + ": " + sqrt(4));
    ^
    1 error
    >
    >
    Is you sqrt function even made? If not then you should make it. If you have
    made the function sqrt, you probably have made it static since you want to
    reference from inside the main function. Unfortunately Java doesnt allow
    that.


    Comment

    • cp

      #3
      Re: syntax error? &quot;cannot find symbol&quot;

      Just going to elaborate on what I said:
      You can't use the arithmetic operators you would normally use on primitives
      (i.e. double) on objects (i.e. Double). eg 1 + sqrt(4).
      If you have made the function sqrt then you can make the function return an
      int or similar. In that way Java will know what the return is
      and the operator can then be applied.

      Also I made the mistake of telling you that you cant reference anything in a
      static context. That is still true but from main you can call static methods
      which will resolve your problem e.g.

      class tal {
      public static void main(String[] arguments) {
      for (int i=0; i<11; i++) {
      System.out.prin tln(i + ": " + sqrt(4));
      }
      }
      public static int sqrt(int a){
      // do something here with a

      return 1;
      }
      }

      Just remember that you can only use the variables given as parameters and
      locally declared variables in a static method.
      You can use the return value


      Comment

      • IchBin

        #4
        Re: syntax error? &quot;cannot find symbol&quot;

        Bjorn Jensen wrote:
        Hi!
        An beginner question:
        Pleas help me with this (-:
        >
        Error (the arrow points on the s in sqrt)
        =====
        tal.java:6: cannot find symbol
        symbol : method sqrt(int)
        location: class tal
        System.out.prin tln(i + ": " + sqrt(4));
        ^
        1 error
        >
        >
        Source
        =====
        class tal {
        public static void main(String[] arguments) {
        for (int i=0; i<11; i++) {
        System.out.prin tln(i + ": " + sqrt(4));
        }
        }
        }
        >
        /Bjorn
        >
        >
        Try this:

        class tal
        {
        public static void main(String[] arguments)
        {
        for (int i = 0; i < arguments.lengt h; i++)
        {
        System.out.prin tln(i + ": " +
        java.lang.Math. sqrt(Double.par seDouble(argume nts[i])));
        }
        }
        }


        Thanks in Advance...
        IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
        _______________ _______________ _______________ _______________ ______________

        'If there is one, Knowledge is the "Fountain of Youth"'
        -William E. Taylor, Regular Guy (1952-)

        Comment

        • Bjorn Jensen

          #5
          Re: syntax error? &quot;cannot find symbol&quot;

          Hi!
          Your example works, but what are I'm doing wrong here:

          import java.lang.Math;

          class tal
          {
          public static void main(String[] arguments)
          {
          for (int i = 0; i < arguments.lengt h; i++)
          {
          System.out.prin tln(i + ": " + sqrt(Double.par seDouble(argume nts[i])));
          }
          }
          }

          Resulting in (arrow at sqrt):
          tal.java:10: cannot find symbol
          symbol : method sqrt(double)
          location: class tal
          System.out.prin tln(i + ": " + sqrt(Double.par seDouble(argume nts[i])));
          ^
          1 error



          Thanks for help!
          Bjørn
          p.s. sorry, for my missing knowledge: is IchBin an name or is a joke;
          IchBin = german for I'm?)


          "IchBin" <weconsul@ptd.n etskrev i en meddelelse
          news:Mx-dnZPkwflLNV7ZUS dV9g@ptd.net...
          Bjorn Jensen wrote:
          >Hi!
          >An beginner question:
          >Pleas help me with this (-:
          >>
          >Error (the arrow points on the s in sqrt)
          >=====
          >tal.java:6: cannot find symbol
          >symbol : method sqrt(int)
          >location: class tal
          > System.out.prin tln(i + ": " + sqrt(4));
          > ^
          >1 error
          >>
          >>
          >Source
          >=====
          >class tal {
          > public static void main(String[] arguments) {
          > for (int i=0; i<11; i++) {
          > System.out.prin tln(i + ": " + sqrt(4));
          > }
          > }
          >}
          >>
          >/Bjorn
          >>
          >>
          Try this:
          >
          class tal
          {
          public static void main(String[] arguments)
          {
          for (int i = 0; i < arguments.lengt h; i++)
          {
          System.out.prin tln(i + ": " +
          java.lang.Math. sqrt(Double.par seDouble(argume nts[i])));
          }
          }
          }
          >
          >
          Thanks in Advance...
          IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
          _______________ _______________ _______________ _______________ ______________
          >
          'If there is one, Knowledge is the "Fountain of Youth"'
          -William E. Taylor, Regular Guy (1952-)

          Comment

          • Bjorn Jensen

            #6
            Re: syntax error? &quot;cannot find symbol&quot;

            Hi!
            I'm just trying to use the built-in funtions pow, sqrt etc
            but can't get it to work.
            Do you know some good examples somewhere, or can You give me one?
            Greetings
            Bjorn

            "cp" <e-blade@nonplayer character.dkskr ev i en meddelelse
            news:44c37876$0 $60783$157c6196 @dreader1.cyber city.dk...
            Just going to elaborate on what I said:
            You can't use the arithmetic operators you would normally use on
            primitives
            (i.e. double) on objects (i.e. Double). eg 1 + sqrt(4).
            If you have made the function sqrt then you can make the function return
            an
            int or similar. In that way Java will know what the return is
            and the operator can then be applied.
            >
            Also I made the mistake of telling you that you cant reference anything in
            a
            static context. That is still true but from main you can call static
            methods
            which will resolve your problem e.g.
            >
            class tal {
            public static void main(String[] arguments) {
            for (int i=0; i<11; i++) {
            System.out.prin tln(i + ": " + sqrt(4));
            }
            }
            public static int sqrt(int a){
            // do something here with a
            >
            return 1;
            }
            }
            >
            Just remember that you can only use the variables given as parameters and
            locally declared variables in a static method.
            You can use the return value
            >
            >

            Comment

            • IchBin

              #7
              Re: syntax error? &quot;cannot find symbol&quot;

              Bjorn Jensen wrote:
              Hi!
              I'm just trying to use the built-in funtions pow, sqrt etc
              but can't get it to work.
              Do you know some good examples somewhere, or can You give me one?
              Greetings
              Bjorn
              >
              "cp" <e-blade@nonplayer character.dkskr ev i en meddelelse
              news:44c37876$0 $60783$157c6196 @dreader1.cyber city.dk...
              >Just going to elaborate on what I said:
              >You can't use the arithmetic operators you would normally use on
              >primitives
              >(i.e. double) on objects (i.e. Double). eg 1 + sqrt(4).
              >If you have made the function sqrt then you can make the function return
              >an
              >int or similar. In that way Java will know what the return is
              >and the operator can then be applied.
              >>
              >Also I made the mistake of telling you that you cant reference anything in
              >a
              >static context. That is still true but from main you can call static
              >methods
              >which will resolve your problem e.g.
              >>
              >class tal {
              > public static void main(String[] arguments) {
              > for (int i=0; i<11; i++) {
              > System.out.prin tln(i + ": " + sqrt(4));
              > }
              > }
              > public static int sqrt(int a){
              > // do something here with a
              >>
              > return 1;
              > }
              >}
              >>
              >Just remember that you can only use the variables given as parameters and
              >locally declared variables in a static method.
              >You can use the return value
              >>
              >>
              >
              >
              Because the package java.lang is so fundamental, all the classes in
              java.lang are automatically imported into every program. It's as if
              every program began with the statement "import java.lang.*;". This is
              why we have been able to use the class name String instead of
              java.lang.Strin g, and Math.sqrt() instead of java.lang.Math. sqrt(). It
              would still, however, be perfectly legal to use the longer forms of the
              names.

              So you can only reference sqrt() as Math.sqrt() java.lang.Math. sqrt()

              Thanks in Advance...
              IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
              _______________ _______________ _______________ _______________ ______________

              'If there is one, Knowledge is the "Fountain of Youth"'
              -William E. Taylor, Regular Guy (1952-)

              Comment

              • IchBin

                #8
                Re: syntax error? &quot;cannot find symbol&quot;

                Bjorn Jensen wrote:
                Hi!
                I'm just trying to use the built-in funtions pow, sqrt etc
                but can't get it to work.
                Do you know some good examples somewhere, or can You give me one?
                Greetings
                Bjorn
                >
                "cp" <e-blade@nonplayer character.dkskr ev i en meddelelse
                news:44c37876$0 $60783$157c6196 @dreader1.cyber city.dk...
                >Just going to elaborate on what I said:
                >You can't use the arithmetic operators you would normally use on
                >primitives
                >(i.e. double) on objects (i.e. Double). eg 1 + sqrt(4).
                >If you have made the function sqrt then you can make the function return
                >an
                >int or similar. In that way Java will know what the return is
                >and the operator can then be applied.
                >>
                >Also I made the mistake of telling you that you cant reference anything in
                >a
                >static context. That is still true but from main you can call static
                >methods
                >which will resolve your problem e.g.
                >>
                >class tal {
                > public static void main(String[] arguments) {
                > for (int i=0; i<11; i++) {
                > System.out.prin tln(i + ": " + sqrt(4));
                > }
                > }
                > public static int sqrt(int a){
                > // do something here with a
                >>
                > return 1;
                > }
                >}
                >>
                >Just remember that you can only use the variables given as parameters and
                >locally declared variables in a static method.
                >You can use the return value
                >>
                >>
                >
                >
                Please do not top post... It makes the messages hard to read.. Look at
                this one and you will see the order problem. Who said what.

                That said, because the package java.lang is so fundamental, all the
                classes in java.lang are automatically imported into every program. It's
                as if every program began with the statement "import java.lang.*;". This
                is why we have been able to use the class name String instead of
                java.lang.Strin g, and Math.sqrt() instead of java.lang.Math. sqrt(). It
                would still, however, be perfectly legal to use the longer forms of the
                names.

                So you can only reference sqrt() as Math.sqrt() java.lang.Math. sqrt()

                Thanks in Advance...
                IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
                _______________ _______________ _______________ _______________ ______________

                'If there is one, Knowledge is the "Fountain of Youth"'
                -William E. Taylor, Regular Guy (1952-)

                Comment

                • IchBin

                  #9
                  Re: syntax error? &quot;cannot find symbol&quot;

                  Bjorn Jensen wrote:
                  Hi!
                  Your example works, but what are I'm doing wrong here:
                  >
                  import java.lang.Math;
                  >
                  class tal
                  {
                  public static void main(String[] arguments)
                  {
                  for (int i = 0; i < arguments.lengt h; i++)
                  {
                  System.out.prin tln(i + ": " + sqrt(Double.par seDouble(argume nts[i])));
                  }
                  }
                  }
                  >
                  Resulting in (arrow at sqrt):
                  tal.java:10: cannot find symbol
                  symbol : method sqrt(double)
                  location: class tal
                  System.out.prin tln(i + ": " + sqrt(Double.par seDouble(argume nts[i])));
                  ^
                  1 error
                  >
                  >
                  >
                  Thanks for help!
                  Bjørn
                  p.s. sorry, for my missing knowledge: is IchBin an name or is a joke;
                  IchBin = german for I'm?)
                  >
                  >
                  "IchBin" <weconsul@ptd.n etskrev i en meddelelse
                  news:Mx-dnZPkwflLNV7ZUS dV9g@ptd.net...
                  >Bjorn Jensen wrote:
                  >>Hi!
                  >>An beginner question:
                  >>Pleas help me with this (-:
                  >>>
                  >>Error (the arrow points on the s in sqrt)
                  >>=====
                  >>tal.java:6: cannot find symbol
                  >>symbol : method sqrt(int)
                  >>location: class tal
                  >> System.out.prin tln(i + ": " + sqrt(4));
                  >> ^
                  >>1 error
                  >>>
                  >>>
                  >>Source
                  >>=====
                  >>class tal {
                  >> public static void main(String[] arguments) {
                  >> for (int i=0; i<11; i++) {
                  >> System.out.prin tln(i + ": " + sqrt(4));
                  >> }
                  >> }
                  >>}
                  >>>
                  >>/Bjorn
                  >>>
                  >>>
                  >Try this:
                  >>
                  >class tal
                  >{
                  >public static void main(String[] arguments)
                  >{
                  >for (int i = 0; i < arguments.lengt h; i++)
                  >{
                  >System.out.pri ntln(i + ": " +
                  >java.lang.Math .sqrt(Double.pa rseDouble(argum ents[i])));
                  >}
                  >}
                  >}
                  >>
                  >>
                  >Thanks in Advance...
                  >IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
                  >______________ _______________ _______________ _______________ _______________
                  >>
                  >'If there is one, Knowledge is the "Fountain of Youth"'
                  >-William E. Taylor, Regular Guy (1952-)
                  >
                  >
                  Please do not top post... It makes the messages hard to read.. Look at
                  this one and you will see the order problem. Who said what.

                  That said, because the package java.lang is so fundamental, all the
                  classes in java.lang are automatically imported into every program. It's
                  as if every program began with the statement "import java.lang.*;". This
                  is why we have been able to use the class name String instead of
                  java.lang.Strin g, and Math.sqrt() instead of java.lang.Math. sqrt(). It
                  would still, however, be perfectly legal to use the longer forms of the
                  names.

                  So you can only reference sqrt() as Math.sqrt() or java.lang.Math. sqrt()

                  Thanks in Advance...
                  IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
                  _______________ _______________ _______________ _______________ ______________

                  'If there is one, Knowledge is the "Fountain of Youth"'
                  -William E. Taylor, Regular Guy (1952-)

                  Comment

                  • IchBin

                    #10
                    Re: syntax error? &quot;cannot find symbol&quot;

                    Bjorn Jensen wrote:
                    Hi!
                    Your example works, but what are I'm doing wrong here:
                    >
                    import java.lang.Math;
                    >
                    class tal
                    {
                    public static void main(String[] arguments)
                    {
                    for (int i = 0; i < arguments.lengt h; i++)
                    {
                    System.out.prin tln(i + ": " + sqrt(Double.par seDouble(argume nts[i])));
                    }
                    }
                    }
                    >
                    Resulting in (arrow at sqrt):
                    tal.java:10: cannot find symbol
                    symbol : method sqrt(double)
                    location: class tal
                    System.out.prin tln(i + ": " + sqrt(Double.par seDouble(argume nts[i])));
                    ^
                    1 error
                    >
                    >
                    >
                    Thanks for help!
                    Bjørn
                    p.s. sorry, for my missing knowledge: is IchBin an name or is a joke;
                    IchBin = german for I'm?)
                    >
                    >
                    "IchBin" <weconsul@ptd.n etskrev i en meddelelse
                    news:Mx-dnZPkwflLNV7ZUS dV9g@ptd.net...
                    >Bjorn Jensen wrote:
                    >>Hi!
                    >>An beginner question:
                    >>Pleas help me with this (-:
                    >>>
                    >>Error (the arrow points on the s in sqrt)
                    >>=====
                    >>tal.java:6: cannot find symbol
                    >>symbol : method sqrt(int)
                    >>location: class tal
                    >> System.out.prin tln(i + ": " + sqrt(4));
                    >> ^
                    >>1 error
                    >>>
                    >>>
                    >>Source
                    >>=====
                    >>class tal {
                    >> public static void main(String[] arguments) {
                    >> for (int i=0; i<11; i++) {
                    >> System.out.prin tln(i + ": " + sqrt(4));
                    >> }
                    >> }
                    >>}
                    >>>
                    >>/Bjorn
                    >>>
                    >>>
                    >Try this:
                    >>
                    >class tal
                    >{
                    >public static void main(String[] arguments)
                    >{
                    >for (int i = 0; i < arguments.lengt h; i++)
                    >{
                    >System.out.pri ntln(i + ": " +
                    >java.lang.Math .sqrt(Double.pa rseDouble(argum ents[i])));
                    >}
                    >}
                    >}
                    >>
                    >>
                    >Thanks in Advance...
                    >IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
                    >______________ _______________ _______________ _______________ _______________
                    >>
                    >'If there is one, Knowledge is the "Fountain of Youth"'
                    >-William E. Taylor, Regular Guy (1952-)
                    >
                    >
                    Please do not top post... It makes the messages hard to read.. Look at
                    this one and you will see the order problem. Who said what.

                    That said, because the package java.lang is so fundamental, all the
                    classes in java.lang are automatically imported into every program. It's
                    as if every program began with the statement "import java.lang.*;". This
                    is why we have been able to use the class name String instead of
                    java.lang.Strin g, and Math.sqrt() instead of java.lang.Math. sqrt(). It
                    would still, however, be perfectly legal to use the longer forms of the
                    names.

                    So you can only reference sqrt() as Math.sqrt() or java.lang.Math. sqrt()

                    Thanks in Advance...
                    IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
                    _______________ _______________ _______________ _______________ ______________

                    'If there is one, Knowledge is the "Fountain of Youth"'
                    -William E. Taylor, Regular Guy (1952-)

                    Comment

                    • IchBin

                      #11
                      Re: syntax error? &quot;cannot find symbol&quot;

                      IchBin wrote:
                      Bjorn Jensen wrote:
                      >Thanks for help!
                      >Bjørn
                      >p.s. sorry, for my missing knowledge: is IchBin an name or is a joke;
                      >IchBin = german for I'm?)
                      Its just a handle. Although it could be considered a statement... lol

                      Thanks in Advance...
                      IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
                      _______________ _______________ _______________ _______________ ______________

                      'If there is one, Knowledge is the "Fountain of Youth"'
                      -William E. Taylor, Regular Guy (1952-)

                      Comment

                      • IchBin

                        #12
                        Re: syntax error? &quot;cannot find symbol&quot;

                        Bjorn Jensen wrote:
                        >>
                        >Thanks for help!
                        >Bjørn
                        >p.s. sorry, for my missing knowledge: is IchBin an name or is a joke;
                        >IchBin = german for I'm?)
                        >>
                        It is just a handle. Although it could be considered a philosophical
                        statement as: 'I am'... lol

                        Or folly like the original name of the "Monty Python Show" which had a
                        name of "It's". That is why when you see some of the original shows they
                        had a guy in the start of the show say "It's"...

                        Thanks in Advance...
                        IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
                        _______________ _______________ _______________ _______________ ______________

                        'If there is one, Knowledge is the "Fountain of Youth"'
                        -William E. Taylor, Regular Guy (1952-)

                        Comment

                        • cp

                          #13
                          Re: syntax error? &quot;cannot find symbol&quot;

                          I suggest you use your favorite search engine to look for examples. using
                          Java + sqrt as criteria to google resulted in a lot
                          of different hits.

                          -cp


                          Comment

                          • Peter Van Weert

                            #14
                            Re: syntax error? &quot;cannot find symbol&quot;

                            So you can only reference sqrt() as Math.sqrt() or java.lang.Math. sqrt()
                            >
                            That is not quite true any more. As of Java 1.5 you can use a static
                            import like:

                            static import java.lang.Math. *;

                            and refer to the method simply as sqrt(...). For more info:


                            Cheers,
                            Peter

                            Comment

                            • Bjorn Jensen

                              #15
                              Re: syntax error? &quot;cannot find symbol&quot;

                              Thank you to all of you for helpfull advice ;-)
                              /Bjorn

                              "Bjorn Jensen" <b.d.jensenremv oe@gmx.netskrev i en meddelelse
                              news:44c361de$0 $3482$ba624c82@ nntp02.dk.telia .net...
                              Hi!
                              An beginner question:
                              Pleas help me with this (-:
                              >
                              Error (the arrow points on the s in sqrt)
                              =====
                              tal.java:6: cannot find symbol
                              symbol : method sqrt(int)
                              location: class tal
                              System.out.prin tln(i + ": " + sqrt(4));
                              ^
                              1 error
                              >
                              >
                              Source
                              =====
                              class tal {
                              public static void main(String[] arguments) {
                              for (int i=0; i<11; i++) {
                              System.out.prin tln(i + ": " + sqrt(4));
                              }
                              }
                              }
                              >
                              /Bjorn
                              >
                              >

                              Comment

                              Working...