Whether it is possible to assign the result of a for loop (for example, a comparison) to one variable in order to work further with the value of this variable outside the loop.

for (int i = 0; i < 100; i++) { int max=1; int a = Integer.parseInt(reader.readLine()); if (a>max) max = a; } 

    1 answer 1

    And what's stopping you? Probably only the scope of a variable local to the block in brackets. Take out its announcement above, and it will be available after the end of the block. max example

      int max=1; for (int i = 0; i < 100; i++) { int a = Integer.parseInt(reader.readLine()); if (a>max) max = a; } system.out.println(max); 
    • Yes, thanks, figured it out. - Alexandr Wake