如何解决程序显示错误“类型为Scanner的nextInt方法未定义”:我该怎么办?
import java.util.*;
class Scanner {
public static void main(){
Scanner sc = new Scanner();
System.out.println("enter a number ");
int a = sc.nextInt();
System.out.println("the number you entered is "+a);
}
}
解决方法
不建议将类的名称与“普通软件包”的名称相同,例如“扫描仪”。您应该更改班级名称,错误将会消失。
,更改班级名称,
class Any_name_other_than_Scanner{
在“扫描仪”定义中尝试一下,
Scanner sc =new Scanner(System.in);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。