How to use comma for 2 or more variables in for statement in Java?

In Java, two or more variables can be declared in a single for statement. This is done to minimize the size of the code for large programs.

For Example:

class test {

public static void main(String args[]) {

int i, j;

for(i=1, j=10; i<j; i++, j–) {

System.out.println(“i = ” + i);

System.out.println(“j = ” + j);




Leave a Reply