如何更改 java 中循环外使用的 while 循环中的变量

how to change variables in a while-loop used outside the loop in java

(...)
int x = 1;
int y = 1;
System.out.println(x);

while ( y == 1)
{
 x = 2;
 y = y + 1;
}

之后如何更改 System.out.println 的 x?

I wrote it very easy but I want to change the x in the while loop and use it at the beginning

你不能。您必须在 while 循环 之后将 System.out.println 行移动到 以使用新计算的值。