当我编写一个用于在java中获取用户输入的简单程序时,我遇到了错误。请帮忙。 [英] I'm getting errors when I write a simple program for getting the user input in java. Please help.

查看:64
本文介绍了当我编写一个用于在java中获取用户输入的简单程序时,我遇到了错误。请帮忙。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个简单的代码来制作程序以获取用户输入我已经从教程网站复制了代码。那个在运行程序时编写代码的人运行得很好。但是当我运行它时会给我带来一些错误。我想我使用的是错误的JDK和JRE。我正在使用版本8更新92.请指导我。当我运行代码时,它说没有为扫描程序定义nextLine()方法。我应该使用JRE 7吗?



我尝试过:



import java.util.Scanner;

public class Scanner {

public static void main(String args []){

Scanner input = new Scanner(System.in);

String value = input.nextLine();



}

}

解决方案

您已声明您的班级名称as Scanner ,这意味着当您调用 nextLine()时,它会在您的类中查找该方法名称,而不是在 java.util.Scanner 类中。将你的课程和程序重命名为独特的东西。



如果你想学习Java,那么最好的教程是 Java& trade;教程 [ ^ ]。

I've used a simple code of making a program to get user input I've copied the code from a tutorial site. The man who'd written the code when he runs the program it runs perfectly. But when I run it gives me several errors. I think I'm using the wrong JDK and JRE. I'm using version 8 update 92. Please guide me. When I run the code it says that the method nextLine() is undefined for the scanner. Should I use JRE 7?

What I have tried:

import java.util.Scanner;
public class Scanner {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
String value = input.nextLine();

}
}

解决方案

You have declared your class name as Scanner, which means that when you call nextLine() it looks for that method name in your class, rather than in the java.util.Scanner class. Rename your class and program to something unique.

If you want to learn Java then the best tutorials are at The Java™ Tutorials[^].


这篇关于当我编写一个用于在java中获取用户输入的简单程序时,我遇到了错误。请帮忙。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆