Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

syntax error? "cannot find symbol"

Thread view: 
Bjorn Jensen - 23 Jul 2006 12:46 GMT
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.println(i + ": " + sqrt(4));
                                   ^
1 error

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

/Bjorn
cp - 23 Jul 2006 13:48 GMT
> Hi!
> An beginner question:
[quoted text clipped - 8 lines]
>                                     ^
> 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.
cp - 23 Jul 2006 14:25 GMT
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.println(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
Bjorn Jensen - 23 Jul 2006 20:50 GMT
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

> Just going to elaborate on what I said:
> You can't use the arithmetic operators you would normally use on
[quoted text clipped - 27 lines]
> locally declared variables in a static method.
> You can use the return value
IchBin - 23 Jul 2006 21:24 GMT
> Hi!
> I'm just trying to use the built-in funtions pow, sqrt etc
[quoted text clipped - 34 lines]
>> 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.String, 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-)
IchBin - 23 Jul 2006 21:28 GMT
> Hi!
> I'm just trying to use the built-in funtions pow, sqrt etc
[quoted text clipped - 34 lines]
>> 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.String, 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-)
cp - 24 Jul 2006 09:09 GMT
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
IchBin - 23 Jul 2006 17:50 GMT
> Hi!
> An beginner question:
[quoted text clipped - 20 lines]
>
> /Bjorn

Try this:

class tal
{
    public static void main(String[] arguments)
    {
        for (int i = 0; i < arguments.length; i++)
        {
            System.out.println(i + ": " +
                    java.lang.Math.sqrt(Double.parseDouble(arguments[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-)
Bjorn Jensen - 23 Jul 2006 20:48 GMT
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.length; i++)
{
System.out.println(i + ": " + sqrt(Double.parseDouble(arguments[i])));
}
}
}

Resulting in (arrow at sqrt):
tal.java:10: cannot find symbol
symbol  : method sqrt(double)
location: class tal
System.out.println(i + ": " + sqrt(Double.parseDouble(arguments[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?)

>> Hi!
>> An beginner question:
[quoted text clipped - 41 lines]
> 'If there is one, Knowledge is the "Fountain of Youth"'
> -William E. Taylor,  Regular Guy (1952-)
IchBin - 23 Jul 2006 21:30 GMT
> Hi!
> Your example works, but what are I'm doing wrong here:
[quoted text clipped - 70 lines]
>> '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.String, 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-)
IchBin - 23 Jul 2006 21:35 GMT
>> 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-)
IchBin - 23 Jul 2006 21:43 GMT
>> 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-)
IchBin - 23 Jul 2006 21:31 GMT
> Hi!
> Your example works, but what are I'm doing wrong here:
[quoted text clipped - 70 lines]
>> '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.String, 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-)
Peter Van Weert - 24 Jul 2006 18:40 GMT
> 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:
http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html

Cheers,
Peter
IchBin - 24 Jul 2006 21:53 GMT
>> So you can only reference sqrt() as Math.sqrt() or java.lang.Math.sqrt()
>>
[quoted text clipped - 8 lines]
> Cheers,
> Peter

Thanks for the info. I forgot about that...

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-)
Bjorn Jensen - 24 Jul 2006 21:32 GMT
Thank you to all of you for helpfull advice ;-)
/Bjorn

> Hi!
> An beginner question:
[quoted text clipped - 20 lines]
>
> /Bjorn


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.