Joystick is returning value 1 even when I'm not pressing the button

Hello.

I'm trying to learn about the joystick module and this is the code I'm working on.

int x = A0;
int y = A1;
int button = 2;

void setup()

{
Serial.begin(9600);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(2,INPUT);
}


void loop() 

{
int xstate = analogRead(A0);
int ystate = analogRead(A1);
int buttonstate = digitalRead(2);

Serial.print("xstate: ");
Serial.print(xstate);
Serial.print("\t");
Serial.print("ystate: ");
Serial.print(ystate);
Serial.print("\t");
Serial.print("buttonstate: ");
Serial.println(buttonstate);

delay(400);
}

For now everything is working fine. But the switch is giving me values 0 and 1 continuously even when I'm not pressing it.

The format is like something like 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0

I'm not sure what's wrong. I checked the wiring too.

Pin 2 is floating. set it to INPUT_PULLUP
Connect the button to pull the pin to GND to activate.

THANK YOU. It's working now.