0

very new to the community. I was wondering if someone could explain why my last println creates a compilation error? Thank you.

 int beer = 62;
   int pizza = 99;
   int total;
   total = pizza + beer;

   System.out.println();
   System.out.println("5. Sum of two numbers");
   System.out.println(beer " + " pizza " = " total);

1 Answers1

1

Should be like this :

System.out.println(beer + " + " + pizza +  " = "  + total);

Note : That we do concatenation in Java using the operator + when atleast one of two operator is of String type.

jack jay
  • 2,463
  • 1
  • 12
  • 26
Mouad EL Fakir
  • 3,509
  • 2
  • 21
  • 37