java code is showing error. ( ‘;’,expected)

You can’t have statements in the class body (z=x*y;). You have (at least) two options:

  • int z = x * y;
  • use initializer block{ z = x * y; }

These are virtually the same. I’d prefer the first option (cleaner) See here

Leave a Comment