Can a local variable be used out of a method?

前端 未结 3 547
广开言路
广开言路 2021-01-26 11:53

I\'ve got stuck in a problem about local variables.

The following is not my original code but I use a simple example to present my question:

import java.         


        
3条回答
  •  南方客
    南方客 (楼主)
    2021-01-26 12:09

        public static void main(String[] args) 
       {
            Scanner userScan=new Scanner(System.in);    
            int input1;
            do{
                input1=userScan.nextInt();
            }while(input1>10);
        }
    

    just declare input1 outside of the scope of do while loop

提交回复
热议问题