how to use input in different loops

I have the following error

cannot find symbol: variable num

in all the if statements.

This is my current code.

Scanner console = new Scanner(System.in);
 int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;

do{System.out.println("Type a number (or -1 to stop): ");
   int num = console.nextInt();
  }while(!num == -1);{
   System.out.print(+ num );
   }if (min < num) {
       num = min;
   }if (num > max) {
         max = num;
      } 
     
    System.out.println("maximum was : " + max);
   System.out.println("minimum was : " + min);
}

Help.



Read more here: https://stackoverflow.com/questions/66344795/how-to-use-input-in-different-loops

Content Attribution

This content was originally published by Mental Overload at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: