Error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Error

Although I have used the import statement here, It says "The method Scanner(InputStream) is undefined for the type student" How can I resolve it? Code: import java.util.Scanner; class student { String usn; Scanner scan=new Scanner(System.in); // error here void read() { System.out.println("enter usn"); usn=scan.nextLine(); .........

31st May 2018, 2:07 PM
Rachita Nayak
Rachita Nayak - avatar
1 Answer
+ 1
Hi Rachita Nayak , it seems that you forget main method. I cleaned your code. Please Try this- import java.util.Scanner; class student { public static void main(String args[]){ String usn; Scanner scan=new Scanner(System.in); System.out.println("enter usn"); usn=scan.nextLine(); System.out.println(usn); } }
31st May 2018, 2:28 PM
Sachin Artani
Sachin Artani - avatar