Alternative to digitalRead? mini piano

I tried to make a mini piano (only one octave as the arduino Uno only has 12 digital pins)

it cheks if a pin is high and if it is, it then plays a sound

i just run a wire between +5v and the pin i'm trying to get high

The problem is that digitalRead can go between high and low randomly if it is not connected to anything so each time i reset the arduino a different sound ( or no sound) plays even if none of the pins are connected to 5v (and never stops playing)

What is the right way to do this? here's my code

const int buzzer = A0; //buzzer to pin A0
int tecla1;            //store the value of digitalread for each key
int tecla2;
int tecla3;
int tecla4;
int tecla5;
int tecla6;
int tecla7;
int tecla8;
int tecla9;
int tecla10;
int tecla11;
int tecla12;

void setup(){
  
pinMode(2, INPUT);  //set input and output pins
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT); 
pinMode(buzzer, OUTPUT);

tecla1 = digitalRead(2);  //checks if each pin is high or low and stores the value in "tecla"
tecla2 = digitalRead(3);
tecla3 = digitalRead(4);
tecla4 = digitalRead(5);
tecla5 = digitalRead(6);
tecla6 = digitalRead(7);
tecla7 = digitalRead(8);
tecla8 = digitalRead(9);
tecla9 = digitalRead(10);
tecla10 = digitalRead(11);
tecla11 = digitalRead(12);
tecla12 = digitalRead(13);

}

void loop(){

 if (tecla1 == HIGH){
  tone(buzzer, 400);
 }
 else if (tecla2 == HIGH){
  tone(buzzer, 450);
 }
 else if (tecla3 == HIGH){
  tone(buzzer, 500);
 }
 else if (tecla4 == HIGH){
  tone(buzzer, 550);
 }
 else if (tecla5 == HIGH){
  tone(buzzer, 600);
 }
 else if (tecla6 == HIGH){
  tone(buzzer, 650);
 }
 else if (tecla7 == HIGH){
  tone(buzzer, 700);
 }
 else if (tecla8 == HIGH){
  tone(buzzer, 750);
 }
 else if (tecla9 == HIGH){
  tone(buzzer, 800);
 }
 else if (tecla10 == HIGH){
  tone(buzzer, 850);
 }
 else if (tecla11 == HIGH){
  tone(buzzer, 900);
 }
 else if (tecla12 == HIGH){
  tone(buzzer, 950);
 }
 else {
  noTone(buzzer);
  delay(100);
  }
  
}

What is the right way to do this?

With pullup resistors. Use the in-built ones.

When you find variables with consecutive numeric suffixes, with arrays, swapping suffixes for indices.

Connect all the switches to ground, and the code I have posted here is using INPUT_PULLUP, which makes a weak pullup on the switches.

const int buzzer = A0; //buzzer to pin A0
int tecla1;            //store the value of digitalread for each key
int tecla2;
int tecla3;
int tecla4;
int tecla5;
int tecla6;
int tecla7;
int tecla8;
int tecla9;
int tecla10;
int tecla11;
int tecla12;

void setup(){
 
pinMode(2, INPUT_PULLUP);  //set INPUT_PULLUP and output pins
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);

tecla1 = digitalRead(2);  //checks if each pin is LOW or low and stores the value in "tecla"
tecla2 = digitalRead(3);
tecla3 = digitalRead(4);
tecla4 = digitalRead(5);
tecla5 = digitalRead(6);
tecla6 = digitalRead(7);
tecla7 = digitalRead(8);
tecla8 = digitalRead(9);
tecla9 = digitalRead(10);
tecla10 = digitalRead(11);
tecla11 = digitalRead(12);
tecla12 = digitalRead(13);

}

void loop(){

 if (tecla1 == LOW){
  tone(buzzer, 400);
 }
 else if (tecla2 == LOW){
  tone(buzzer, 450);
 }
 else if (tecla3 == LOW){
  tone(buzzer, 500);
 }
 else if (tecla4 == LOW){
  tone(buzzer, 550);
 }
 else if (tecla5 == LOW){
  tone(buzzer, 600);
 }
 else if (tecla6 == LOW){
  tone(buzzer, 650);
 }
 else if (tecla7 == LOW){
  tone(buzzer, 700);
 }
 else if (tecla8 == LOW){
  tone(buzzer, 750);
 }
 else if (tecla9 == LOW){
  tone(buzzer, 800);
 }
 else if (tecla10 == LOW){
  tone(buzzer, 850);
 }
 else if (tecla11 == LOW){
  tone(buzzer, 900);
 }
 else if (tecla12 == LOW){
  tone(buzzer, 950);
 }
 else {
  noTone(buzzer);
  delay(100);
  }
 
}

TheMemberFormerlyKnownAsAWOL:
With pullup resistors. Use the in-built ones.

When you find variables with consecutive numeric suffixes, with arrays, swapping suffixes for indices.

… and connect that test input to GND for testing.