/* * Explore the java rules of Scope -- ie when variables are alive * * Created: August 2023 * @author gtowell * adapted from c murphy */ public class Scoper { public static void main(String[] args) { int a = 4; int b = 1; if (b > 0) { a = 3; } System.out.println(a); // okay! int x = 5; if (x > 0) { int y = 7; System.out.println(x + y); } System.out.println(y); // no! int m = -2; int n = 4; if (n > 0) { int m = 2; // no! allowed in some cases but not here } System.out.println(m + n); } }