语法错误? “找不到符号” [英] syntax error? "cannot find symbol"

查看:56
本文介绍了语法错误? “找不到符号”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

一个初学者问题:

请求帮助我( - :


错误(箭头指向)在sqrt中的s)

=====

tal.java:6:找不到符号

符号:方法sqrt(int )

位置:class tal

System.out.println(i +":" + sqrt(4));

^

1错误

来源

=====

class tal {

public static void main(String [] arguments){

for(int i = 0; i< 11; i ++){

System.out.println(i + ":" + sqrt(4));

}

}

}


/ Bjorn

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

推荐答案



" Bjorn Jensen" b。********* *****@gmx.net写在留言中

新闻:44 ********************** @ nntp02.dk.telia .net .. ..

"Bjorn Jensen" <b.**************@gmx.netwrote in message
news:44**********************@nntp02.dk.telia.net. ..

嗨!

一个初学者问题:

请求帮助我( - :


错误(a在sqrt的s上的rrow点)

=====

tal.java:6:找不到符号

符号:方法sqrt (int)

location:class tal

System.out.println(i +":" + sqrt(4));

^

1错误

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



你是sqrt函数吗甚至做过?如果没有,那么你应该做到。如果你有

的函数sqrt,你可能已经把它设为静态,因为你想从main函数里面引用
引用。不幸的是Java不允许

那个。

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.


只是详细说明我说的话:

你可以''使用通常用于原语的算术运算符

(即double)对象(即Double)。例如1 + sqrt(4)。

如果您已经创建了函数sqrt,那么您可以使函数返回

int或类似函数。通过这种方式,Java将知道返回是什么
然后可以应用运算符。


我还错误地告诉你,你不能参考

静态上下文中的任何内容。这仍然是正确的,但从主要你可以调用静态方法

这将解决你的问题,例如


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){

//在这里做点什么


返回1;

}

}


请记住,你只能在静态方法中使用作为参数给出的变量和

本地声明的变量。

你可以使用返回值
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写道:
Bjorn Jensen wrote:

嗨!

初学者问题:

请求帮助我( - :


错误(在sqrt中s上的箭头点)

=====

tal.java:6:找不到符号

符号:方法sqrt(int)

loca :class tal

System.out.println(i +":" + sqrt(4));

^

1错误


来源

=== ==

class tal {

public static void main(String [] arguments){

for(int i = 0; i< 11 ; i ++){

System.out.println(i +":" + sqrt(4));

}

}

}


/ Bjorn

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



试试这个:


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])));

}

}

}

在此先感谢...

IchBin,Pocono Lake,Pa,USA http://weconsultants.phpnet.us

______________________________ ____________________ ________________________


''如果有的话,知识就是青春之泉''

-William E. Taylor,Regular Guy(1952) - )

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-)


这篇关于语法错误? “找不到符号”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆