java - Java代码pls错误

标签 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] + "." );
}

请帮帮我!!谢谢!!!

最佳答案

摘自您在评论中提到的书。 。在此代码之后...书中的声明是:
enter image description here

Whew! Aren't you glad you don't ahve to do that every time you use a variable ??



您需要的是以下内容:
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 + "." );
}

关于java - Java代码pls错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42810033/

相关文章:

java - 隐式和显式 ArrayList 大小声明之间的区别?

java - Java ThreadPoolExecutor 测量任务在执行之前在队列中等待的时间

python - 字符串在 python 中 float 时遇到问题

compiler-errors - 编译器错误堆栈跟踪

ios - Xcode 7.0.1 with CocoaPods 应用程序编译错误退出代码 1

java - CacheLoader 多次加载相同的键

java - ComboBox 作为 JTable 的 CellRenderer

error-handling - Rust 是否有提前返回错误的钩子(Hook)?

php注册用户报错

java - 为什么类型的空变量声明显示编译错误而不是空声明?