-5

Hi im new in java and tried to make this piece of code to work but i can't concatenate the variables

public class peces {
        public static void main(String args[]){
        String raza = "Barracuda";
        String alimento = "otros peces";
        int peso = "20";
        System.out.println ("El Peso de la" +raza "es de " +peso "kg y se alimenta de " +alimeto);
        }
}
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
Alex
  • 5
  • 1
  • 2

1 Answers1

1

You need to add a + before each value you add, so a + after raza (not just before), peso and so on.

Thats how string concatenation works in Java.

Like this:

System.out.println ("El Peso de la" + raza + "es de " + peso + "kg y se alimenta de " + alimeto);

See

Community
  • 1
  • 1
flotothemoon
  • 1,882
  • 2
  • 20
  • 37