I wrote a java program and it is not behaving as expecting. This is the code:
Code:
public class test{
static MyPoint[] p = new MyPoint[3];
public static void printPoints(){
System.out.println( " x = " + p[0].x + " y = " + p[0].y);
System.out.println( " x = " + p[1].x + " y = " + p[1].y);
System.out.println( " x = " + p[2].x + " y = " + p[2].y);
}
public static void main(String[] args) {
p[0].x = 0.0f;
p[0].y = 0.0f;
p[1].x = 0.12f;
p[1].y = 0.13f;
p[2].x = 0.367878f;
p[2].y = 0.756785f;
printPoints();
}
}
class MyPoint{
public static float x;
public static float y;
}
I would expect the output of this program to be:
Code:
x = 0.0 y = 0.0
x = 0.12 y = 0.13
x = 0.367878 y = 0.756785
But instead, the output is:
Code:
x = 0.367878 y = 0.756785
x = 0.367878 y = 0.756785
x = 0.367878 y = 0.756785
I'm pulling my hair out trying to figure out why this is happening. Does anyone know what it is I'm overlooking?