Java这段代码有什么问题?

时间:2013-09-06 18:54:35

标签: java

class Ages {
    public static void main (String args[]){
        int age = 3;
        Scanner agescan = new Scanner(System.in);
        System.out.println("Hello. Enter your age here: ");
        age = agescan.nextInt();
    }           
}

我正在尝试根据您的年龄创建一些可以说某件事的东西。我还没有添加嵌套的if和else东西,因为这不会运行..为什么?

这是我的错误消息:

Exception in thread "main" java.lang.NoClassDefFoundError: Age Caused by:
    java.lang.ClassNotFoundException: Age at
    java.net.URLClassLoader$1.run(URLClassLoader.java:202) at
    java.security.AccessController.doPrivileged(Native Method) at
    java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
    java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
    sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
    java.lang.ClassLoader.loadClass(ClassLoader.java:247)

1 个答案:

答案 0 :(得分:2)

您的代码没有任何错误。我跑了进入年龄后你按下了Enter吗?

import java.util.Scanner;

class Ages {
    public static void main(String args[]) {
        int age = 3;
        Scanner agescan = new Scanner(System.in);
        System.out.println("Hello. Enter your age here: ");
        age = agescan.nextInt();

        System.out.println("You entered: " + age);
    }

}