void setup() {
pinMode(2, INPUT);
pinMode(4, OUTPUT);
digitalWrite(2, LOW);
digitalWrite(4,HIGH);
}
This code will make pin 2 a floating input. If it's not connected to anything then it will pick up stray electrical fields from the air and can read high or low at random.
Also, why are you writing to an input?