Sir,
Here is a program to detrmine distance between 2 ponits
There is an error:
Can't make a static reference to nonstatic variable distance in class points.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
class point
{
int x,y;
void getpoint(int a,int b)
{
x=a;
y=b;
}
}
class points
{
float distance;
public static void main(String args[])
{
point p1=new point();
point p2=p1;
point p3=new point();
point p4=new point();
p1.getpoint(5,10);
p2.getpoint(15,20);
p3.getpoint(20,30);
p4.getpoint(30,40);
System.out.println("x1="+p1.x+"y1="+p1.y);
p1=null;
System.out.println("x2="+p2.x+"y2="+p2.y);
p2=null;
int dx=p3.x-p4.x;
int dy=p3.y-p4.y;
distance=Math.sqrt(dx*dx+dy*dy);
System.out.println("Distance ="+distance);
}
}
Comments
: Here is a program to detrmine distance between 2 ponits
: There is an error:
: Can't make a static reference to nonstatic variable distance in class points.
:
:
: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:
: class point
: {
: int x,y;
: void getpoint(int a,int b)
: {
: x=a;
: y=b;
: }
: }
: class points
: {
: float distance;
: public static void main(String args[])
: {
: point p1=new point();
: point p2=p1;
: point p3=new point();
: point p4=new point();
: p1.getpoint(5,10);
: p2.getpoint(15,20);
: p3.getpoint(20,30);
: p4.getpoint(30,40);
: System.out.println("x1="+p1.x+"y1="+p1.y);
: p1=null;
: System.out.println("x2="+p2.x+"y2="+p2.y);
: p2=null;
: int dx=p3.x-p4.x;
: int dy=p3.y-p4.y;
: distance=Math.sqrt(dx*dx+dy*dy);
: System.out.println("Distance ="+distance);
: }
: }
:
:
:
:
Make the main() nonstatic would be the easiest solution.
: : Here is a program to detrmine distance between 2 ponits
: : There is an error:
: : Can't make a static reference to nonstatic variable distance in class points.
: :
: :
: : :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: :
: : class point
: : {
: : int x,y;
: : void getpoint(int a,int b)
: : {
: : x=a;
: : y=b;
: : }
: : }
: : class points
: : {
: : float distance;
: : public static void main(String args[])
: : {
: : point p1=new point();
: : point p2=p1;
: : point p3=new point();
: : point p4=new point();
: : p1.getpoint(5,10);
: : p2.getpoint(15,20);
: : p3.getpoint(20,30);
: : p4.getpoint(30,40);
: : System.out.println("x1="+p1.x+"y1="+p1.y);
: : p1=null;
: : System.out.println("x2="+p2.x+"y2="+p2.y);
: : p2=null;
: : int dx=p3.x-p4.x;
: : int dy=p3.y-p4.y;
: : distance=Math.sqrt(dx*dx+dy*dy);
: : System.out.println("Distance ="+distance);
: : }
: : }
: :
: :
: :
: :
: Make the main() nonstatic would be the easiest solution.
:
Stil have problem
there is an error:: Typr expected
: : : Here is a program to detrmine distance between 2 ponits
: : : There is an error:
: : : Can't make a static reference to nonstatic variable distance in class points.
: : :
: : :
: : : :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: : :
: : : class point
: : : {
: : : int x,y;
: : : void getpoint(int a,int b)
: : : {
: : : x=a;
: : : y=b;
: : : }
: : : }
: : : class points
: : : {
: : : float distance;
: : : public static void main(String args[])
: : : {
: : : point p1=new point();
: : : point p2=p1;
: : : point p3=new point();
: : : point p4=new point();
: : : p1.getpoint(5,10);
: : : p2.getpoint(15,20);
: : : p3.getpoint(20,30);
: : : p4.getpoint(30,40);
: : : System.out.println("x1="+p1.x+"y1="+p1.y);
: : : p1=null;
: : : System.out.println("x2="+p2.x+"y2="+p2.y);
: : : p2=null;
: : : int dx=p3.x-p4.x;
: : : int dy=p3.y-p4.y;
: : : distance=Math.sqrt(dx*dx+dy*dy);
: : : System.out.println("Distance ="+distance);
: : : }
: : : }
: : :
: : :
: : :
: : :
: : Make the main() nonstatic would be the easiest solution.
: :
:
:
:
:
:
: Stil have problem
: there is an error:: Typr expected
:
:
:
:
:
:
Did you declare it like this:
[code]
public void main(String args[])
[/code]
?
: : : : Here is a program to detrmine distance between 2 ponits
: : : : There is an error:
: : : : Can't make a static reference to nonstatic variable distance in class points.
: : : :
: : : :
: : : : :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: : : :
: : : : class point
: : : : {
: : : : int x,y;
: : : : void getpoint(int a,int b)
: : : : {
: : : : x=a;
: : : : y=b;
: : : : }
: : : : }
: : : : class points
: : : : {
: : : : float distance;
: : : : public void main(String args[])
: : : : {
: : : : point p1=new point();
: : : : point p2=p1;
: : : : point p3=new point();
: : : : point p4=new point();
: : : : p1.getpoint(5,10);
: : : : p2.getpoint(15,20);
: : : : p3.getpoint(20,30);
: : : : p4.getpoint(30,40);
: : : : System.out.println("x1="+p1.x+"y1="+p1.y);
: : : : p1=null;
: : : : System.out.println("x2="+p2.x+"y2="+p2.y);
: : : : p2=null;
: : : : int dx=p3.x-p4.x;
: : : : int dy=p3.y-p4.y;
: : : : distance=Math.sqrt(dx*dx+dy*dy);
: : : : System.out.println("Distance ="+distance);
: : : : }
: : : : }
: : : :
: : : :
: : : :
: : : :
: : : Make the main() nonstatic would be the easiest solution.
: : :
: :
: :
: :
: :
: :
: : Stil have problem
: : there is an error:: Typr expected
: :
: :
: :
: :
: :
: :
: Did you declare it like this:
: [code]
: public void main(String args[])
: [/code]
: ?
:
: Yes sir i declare like this, but it is not compiling:
:plz help