当我运行以下代码时,它显示扫描仪无法解析为类型的错误。我检查了 jre 是否已安装并且版本是 1.7 我还需要检查什么?请帮忙。
public class student {
String name;
int rollno;
public void get(String nm, int rno)
{ name=nm;
rollno=rno;
}
public void display()
{ System.out.println("Name of student is :" +name);
System.out.println("Roll no of student is :" +rollno);
}
public static void main(String args[])
{
int i ;
int r1;
String n1;
student obj[]= new student[10];
Scanner sc=new Scanner(System.in);
for(i=0;i<10;i++)
{
obj[i]= new student();
}
for(i=0;i<10; i++)
{ System.out.println("Enter name:");
n1=sc.next();
sc.nextLine();
System.out.println("Enter roll no :");
r1=sc.nextInt();
obj[i].get(n1,r1) ;
obj[i].display() ;
}
}
}
原文由 user4036695 发布,翻译遵循 CC BY-SA 4.0 许可协议
您还需要导入类本身。在文件的最顶部,在
public class student
之上,您需要添加:此外,我想再提出一些可能的更正:
PascalCase