java代码错误

时间:2017-03-15 12:39:52

标签: java error-handling compiler-errors

我在互联网上有这个代码而我无法运行它们请告诉我  为什么???

public static void main( String[] args ) {
    keyboard[Scanner] = new Scanner(System.in);

    System.out.print( "Hello. What is your name? " );
    name[String] = keyboard[Scanner].next();

    System.out.print( "Hi, " + name[String] + "! How old are you? " );
    age[int] = keyboard[Scanner].nextInt();

    System.out.println("So you're " + age[int] + ", eh? That's not so old.");
    System.out.print( "How much do you weigh, " + name[String] + "? " );
    weight[double] = keyboard[Scanner].nextDouble();

    System.out.println( weight[double] + "! Better keep that quiet!!" );
    System.out.print("Finally, what's your income, " + name[String] + "? " );
    income[double] = keyboard[Scanner].nextDouble();

    System.out.print( "Hopefully that is " + income[double] + " per hour" );
    System.out.println( " and not per year!" );
    System.out.print( "Well, thanks for answering my rude questions, " );
    System.out.println( name[String] + "." );
}

请帮帮我!!感谢!!!

1 个答案:

答案 0 :(得分:1)

来自你在评论中提到的那本书。 。就在这段代码之后...书中的陈述是: enter image description here

  

呼!你很高兴你每次使用变量都不会这样做吗?

您需要的是:

public static void main( String[] args ) {
    Scanner keyboard = new Scanner(System.in);

    System.out.print( "Hello. What is your name? " );
    String name = keyboard.next();

    System.out.print( "Hi, " + name+ "! How old are you? " );
    int age = keyboard.nextInt();

    System.out.println("So you're " + age + ", eh? That's not so old.");
    System.out.print( "How much do you weigh, " + name + "? " );
    double  weight = keyboard.nextDouble();

    System.out.println( weight + "! Better keep that quiet!!" );
    System.out.print("Finally, what's your income, " + name + "? " );
    double income = keyboard.nextDouble();

    System.out.print( "Hopefully that is " + income + " per hour" );
    System.out.println( " and not per year!" );
    System.out.print( "Well, thanks for answering my rude questions, " );
    System.out.println( name + "." );
}