OneBite.Dev - Coding blog in a bite size

assign multiple variables in java

Code snippet on how to assign multiple variables in java

  int x = 10, y = 25, z = 50;

This code snippet assigns the values 10 (for the integer x), 25 (for the integer y) and 50 (for the integer z) in Java. The data type of each variable is an integer. The code first declares three integer variables ‘x’, ‘y’ and ‘z’. The keyword ‘int’ is used to declare the variables as integers. As two variables are being assigned to the same data type, they need to be separated by a comma. Then the values of 10, 25, and 50 are assigned to each respective variable. The assignment of values to each variable is separated by the assignment operator ‘=’. Finally, a semicolon at the end of the line indicates the end of the line and keeps the code readable.

java