+ 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(); .........
1 Respuesta
+ 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);
}
}