0

I'm still learning how Java works, and I've got a long way to go. I've stumbled across this problem and can't seem to figure out where exactly the error(s) are.

public class Test {
    public static void main (String[] args) {
    int i = j = k = 2;
    System.out.println(i + " " + j + " " + k);

    }

}

The lesson has been talking about putting variables together, but I'm at a loss as to where the issue is. When I put the code into NetBeans, I immediately get an error on the "int i = j = k = 2;" line, so I'm assuming it has something to do with that.

Any help is appreciated!

Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382

2 Answers2

3

You need to declare the variables first, then initialize them:

int i, j, k;
i = j = k = 2;
Mohammed Aouf Zouag
  • 17,042
  • 4
  • 41
  • 67
1

You have to first declare them then initialize them:

int i,j,k;
i = j = k = 2;
dequec64
  • 923
  • 1
  • 8
  • 26