JAVA:日食. MyInput.readDouble无法解析 [英] JAVA: eclipse. MyInput.readDouble cannot be resolved

查看:55
本文介绍了JAVA:日食. MyInput.readDouble无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.我在使用一些简单的代码时遇到了麻烦.

Hi. I''m having trouble with a simple bit of code.

answer = MyInput.readDouble();


错误报告以下内容:无法解析MyInput"

我真的不知道问题出在哪里.我是Java的新手.

我包含以下代码:


An error reports the following: ''MyInput cannot be resolved''

I really don''t know what the problem is. I''m new to Java.

I included the following code:

import java.io.*;



非常感谢您的帮助.



Your help is very much appreciated.

推荐答案

这通常意味着代码无法识别该类.可能是MyInput来自另一个库,在这种情况下,您也需要导入该库.
This generally means that the code cannot recognize the class. It might be that MyInput is from another library, in which case, you need to import that library as well.


MyInput是一个自制类,不是任何Java库的一部分.

您应该尝试以下操作之一:

MyInput is a self made class, not part of any Java lib.

You should try one of the following:

Scanner scan = new Scanner(System.in); 
String mySentence = scan.nextLine(); 


它将把System.in(这是标准输入->键盘)引导到您可以读取的扫描仪中.

另一个版本:


which would direct the System.in (which is the standard input -> keyboard) into a scanner which you can read from.

another version:

BufferedReader oReader = new BufferedReader(new InputStreamReader(System.in));
String strRead = oReader.readLine();


...使用BufferedReader为您保存输入.然后您可以阅读它.

这两个版本都需要一些try/catch,eclipse会告诉您并加以注意.这是必需的,因为操作可能会失败,并且如果操作失败,您的代码将无效.


...which uses a BufferedReader to hold the input for you. You can then read from it.

Both versions need some try/catch around it, eclipse will tell you and take care of that. That is needed as the operation can fail and your code would not be valid if the operation fails.


这篇关于JAVA:日食. MyInput.readDouble无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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