Look, you do not have a PULLUP resistor on your input.
Use one.
Either enable the internal PULLUP on the input or use a 10k PULLUP (or pulldown) connected to the pin.
My assumption is that you have a switch connected between Pin 2 and Vcc.
So when switch is actuated, Pin 2 goes high. But when the switch is then released... why would pin 2 stop being high? That pin is configured as an input, so there's nothing to cause the voltage on the pin to go back to logical-0. The only reason it ever changes is that the pin and wire going to the switch will act as an antenna, picking up local electrical noise. You can see this effect very clearly if you use the analog read serial example with nothing connected to it.
And that's why you need a pulldown on pin 2 - i normally default 10k for pullups and pulldowns, but anything from 1k to 100k will work for simple cases.
The other approach is to invert the switch, so it connects pin 2 to gnd, and then set the pin to INPUT_PULLUP, which uses the chip's internal pullup resistors (it doesn't have internal pulldowns)