Re: Variabln in Methode nicht zulässig
- From: Roedy Green <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx>
- Date: Fri, 30 Dec 2005 00:13:11 GMT
On 29 Dec 2005 15:28:12 -0800, mirco_menard@xxxxxxx wrote, quoted or
indirectly quoted someone who said :
>Es geht um eine Klasse, die f=FCr ein rechtwinkliges Dreieck, die
>Hypotenuse berechnen soll.
>In der Methode:
>public static double hypotenuse(double a, double b)
>sind die beiden Variabln 'a' und 'b' in dieser Zeile:
> x =3D Math.sqrt(a*a+b*b);
>scheinbar nicht zul=E4ssig, sie werden rot unterstrichen ( Ich verwende
>Eclipse 3)
>Die Variabln sind aber gleich am Anfangder Classse deklariert und haben
>je eine set und get Methode. Insofern kann ich mir keien reim drauf
>machen warum sie in der Methode "hypotenuse" nicht zul=E4ssig sind ?
Here is a rough translations:
It concerns a class, f=FCr right-angled triangle, computing the
hypotenuse. In the method: public static double hypotenuse(double a,
double b) are the two variables ' a ' and ' b ' in this line: x =
Math.sqrt(a*a+b*b); apparently not legitimate, Eclipse 3 underlines it
in red.
The variables are however defined in this class with getters and
setters. I can't figure out the problem with my hypotenuse method.
public class RechtWDreieck {
private int a;
private int b;
public RechtWDreieck(int a, int b)
{
seta(a);
setb(b);
}
public int geta()
{
return a;
}
public void seta(int a)
{
this.a = a;
}
public int getb()
{
return b;
}
public void setb(int a)
{
this.b = a;
}
public static double hypotenuse(double a, double b)
{
// berechnet die Hypotenuse im rechtwinkligen
Dreick
double x;
x =Math.sqrt(a*a+b*b);
x =Math.round(x*100.0)/100.0;
return x;
}
-----------------------------
your problem would be obvious if you compiled the code with Javac and
looked up the error message at
http://mindprod.com/jgloss/compileerrormessages.html
It would point out you were tryin to use instance variables a and b in
a static method. You need to make a and b static or hypotenuse
instance.
I would dispense with a and b altogether. Just pass them directly to
hyypotenuse as parameters.
see http://mindprod.com/jgloss/static.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.
- References:
- Variabln in Methode nicht zulässig
- From: mirco_menard
- Variabln in Methode nicht zulässig
- Prev by Date: Re: How to enter characters beyond keyboard into JTextField?
- Next by Date: Re: How to enter characters beyond keyboard into JTextField?
- Previous by thread: Variabln in Methode nicht zulässig
- Next by thread: Re: Variablen in Methode nicht zulaessig
- Index(es):