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!

2
  • 2
    variables j and k are unknown. you have to declare with some data types. then you can initialize. Commented Jan 26, 2016 at 14:49
  • 2
    int i,j,k; i = j = k = 2; Commented Jan 26, 2016 at 14:50

2 Answers 2

3

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

int i, j, k;
i = j = k = 2;
Sign up to request clarification or add additional context in comments.

Comments

1

You have to first declare them then initialize them:

int i,j,k;
i = j = k = 2;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.