How to assign the same values to multiple variables in one line with Java

1 Answer

0 votes
class MultipleVariablesOneLineOneValue {
    public static void main(String[] args) {
        int a, b, c, d = c = b = a = 178;
         
        System.out.println(a + " " + b + " " + c + " " + d);
    }
}
 
 
 
/*
run:
 
178 178 178 178
 
*/

 



answered Jul 14, 2025 by avibootz
...