Here is an example, at the end to calculate x you need the variable z2, declared inside the if-else. IDEA highlights it in red, what to do?

public class laba2 { public static void main(String[] args) throws IOException { System.out.println("add b"); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String sb = reader.readLine(); int b = Integer.parseInt(sb); if (b>10) { System.out.println("No solutions"); } else { if (b == 10) { .double z2 = Math.tan(b); } else { double z2 = 1; } } double z1 = (90-b*b)/(Math.sqrt(3*b*b+1)); double x = (z1*z1*z1-1)/(z2*z2+1); double y = 1/Math.tan(x)-Math.sqrt(1+x*x); System.out.println("z1 " +z1+ " z2 " + " x " +x+ " y " +y+ " b " +b); } } 

    2 answers 2

    Declare it outside the block, and in the block make an assignment value.

      In your case, the scope of the variable is the braces of the if block. Declare the variable z2 at the beginning of the method, so that it would be accessible from anywhere in the method.