P: n/a

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  
Share this Question
P: n/a

"Bjorn Jensen" <b.**************@gmx.netwrote in message
news:44**********************@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.println(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.  
P: n/a

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  
P: n/a

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.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
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)  
P: n/a

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?)
"IchBin" <we******@ptd.netskrev i en meddelelse
news:Mx********************@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.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
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)
 
P: n/a

Hi!
I'm just trying to use the builtin 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*****@nonplayercharacter.dkskrev i en meddelelse
news:44***********************@dreader1.cybercity. 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.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
 
P: n/a

Bjorn Jensen wrote:
Hi!
I'm just trying to use the builtin 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*****@nonplayercharacter.dkskrev i en meddelelse
news:44***********************@dreader1.cybercity. 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.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
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)  
P: n/a

Bjorn Jensen wrote:
Hi!
I'm just trying to use the builtin 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*****@nonplayercharacter.dkskrev i en meddelelse
news:44***********************@dreader1.cybercity. 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.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
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)  
P: n/a

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.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?)
"IchBin" <we******@ptd.netskrev i en meddelelse
news:Mx********************@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.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
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(argument s[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.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)  
P: n/a

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.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?)
"IchBin" <we******@ptd.netskrev i en meddelelse
news:Mx********************@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.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
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(argument s[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.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)  
P: n/a

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)  
P: n/a

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)  
P: n/a

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  
P: n/a

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/...icimport.html
Cheers,
Peter  
P: n/a

Thank you to all of you for helpfull advice ;)
/Bjorn
"Bjorn Jensen" <b.**************@gmx.netskrev i en meddelelse
news:44**********************@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.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
 
P: n/a

Peter Van Weert wrote:
>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/...icimport.html
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)   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 27744
 replies: 15
 date asked: Jul 23 '06
