Java:使用键盘类输入字符串 [英] Java: Input strings with keyboard class

查看:451
本文介绍了Java:使用键盘类输入字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Java控制台应用程序中输入信息,但我似乎无法运行它。

I'm trying to input information in Java console application but I can't seem to run it.

这是我的Java文件看起来像: p>




This is how my Java file looks like:

public class Ovning1_3 
{

     public static void main(String args[])
     {

         String name;
         System.out.println("Enter your name");
         name = Keyboard.readString();
         System.out.println(name);      
    }

}





$ b b

但是我得到的错误:


But I get the error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Keyboard cannot be resolved
at Ovning1_3.main(Ovning1_3.java:9)



< hr>

我在源文件夹中有一个keyboard.class文件。
我使用Eclipse和Ubuntu。


I have a keyboard.class file in my source folder. I'm using Eclipse with Ubuntu.

推荐答案

Unresolved compilation problem:  

表示该代码无法编译。

您必须汇入键盘,例如

import uitl.Keyboard

当您使用不同包(不是当前类的同一个包)中的类时,必须导入该类。如果类也在同一个包中,则不需要导入。

When you use classes from a different package (not the same package of the current class), you have to import the class. If the class is also in the same package then you need not import.

类通常分为

如何知道包?去第一个类的。这应该是包xyz ,意味着 xyz 包中的当前类。该类将在一个名为 xyz 的文件夹中(这是包的规则:当你想在包中有一个类时,说 abc .xyz ,那么该类应该有一个包声明 - 代码的第一行 - 要包 abc.xyz ,该文件应该存在在 xyz 中的文件夹 abc

Classes are generally grouped into Packages.
How do you know the package? Go to the first like of the class. This should be something like package xyz meaning that the current class in the xyz package. The class will be in a folder called xyz then (This is the rule for packages: when you want to have a class in a package, say abc.xyz then the class should have a package declaration - the first line of the code - to be package abc.xyz and the file should be present in a folder xyz which in then should be in a folder abc.

这篇关于Java:使用键盘类输入字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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