M
M
Mikhail Smailovich2020-02-13 08:10:09
Java
Mikhail Smailovich, 2020-02-13 08:10:09

Why does not see the variable [c]?

public static void main(String[] args) {
    int k, c, j, a, b, d;
    j = 10;
    b = 2000;
    k = 3000;
    d = 4000;
    a = 1;
    if (j < 100) {
      if (j < 90)
        a = b;
      if (k > j)
        c = k - j;
    } else
      c = d;
    System.out.println(a);
    System.out.println(c);
    System.out.println(k);
  }
}

print claim only on variable [c]:
The local variable c may not have been initialized
Why? How can I print it out?
The example is far-fetched, we are talking only about the visibility of variables, and so, I don’t understand how to display it in the console.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-02-13
@smi33

If j is less than 100 and k is less than j, nothing is assigned to c, so it may be uninitialized at the point of use.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question