How do I fix the error where I cannot make a static reference to a non-static input field?

后端 未结 5 724
刺人心
刺人心 2021-01-26 22:38

I am learning java. I wrote the following code but I am getting this error \"cant make a static reference to a non static input field\" in Arrayfunction(), when I try to take in

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-26 23:03

    The reason for this error is: As you have not created the object the non-static variable input does not exist, so you can not use it. To fix it you can make input as static

    static Scanner input= new Scanner(System.in);
    

提交回复
热议问题