Good day. Such a question - inside the while loop , the value of the variable n is determined, but outside the loop limits it is not available. How can I get him out of there? Is it possible to somehow modify the scope for a variable?
import java.util.Scanner; public class Main { public static void main(String[] args) { boolean j = false; int n; int[] arr1 = new int[n]; while (!j){ System.out.println("Введите четное положительное число"); Scanner inc = new Scanner(System.in); n = inc.nextInt(); if (n > 0 && n%2==0) j=true; } for (int i=0; i <=n; i++) {arr1[i] = (int) (Math.random() * 11 - 5);} }}
за пределам цикла оно не доступно- how did you get this? - post_zeew