Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我必须获得用户';以整数形式保存出生月份,并作为变量存储,以便以后打印_Java_Eclipse - Fatal编程技术网

Java 我必须获得用户';以整数形式保存出生月份,并作为变量存储,以便以后打印

Java 我必须获得用户';以整数形式保存出生月份,并作为变量存储,以便以后打印,java,eclipse,Java,Eclipse,这是我的密码 //输入 System.out.println("Using numbers, in what month were you born? "); String **userMonth** = input.nextLine(); // also tried int **userMonth** = input.nextInt(); 这两种方式都不起作用 userMonth将不会“激活?”(很抱歉,noob不知道所有术语) 稍后在程序错误中尝试调

这是我的密码

//输入

    System.out.println("Using numbers, in what month were you born? ");

    String **userMonth** = input.nextLine();

// also tried int **userMonth** = input.nextInt();
这两种方式都不起作用

userMonth将不会“激活?”(很抱歉,noob不知道所有术语)

稍后在程序错误中尝试调用时:

    if (userMonth < 3) {
    System.out.println("Your vacation home is a van down by a river!"); 
    }
if(用户月份<3){
System.out.println(“你的度假屋是一辆沿河而下的货车!”);
}

//userMonth无法解析为变量

非常奇怪,您的变量显示为
**varName**
,而不是
varName

  • 首次使用:
但它不使用换行符('ENTER')

  • 因此,紧接着,通过以下方式使用换行符:
  • 还要确保扫描仪已声明为
  • 不要忘记在程序结束时关闭扫描仪

这回答了你的问题吗?不,我的代码没有将userMonth变成一个对象,当我稍后尝试引用它时,它没有连接到变量。请发布完整的代码。您是否使用
userMonth
int userMonth = 0; // initialize variable.
userMonth = input.nextInt();
input.nextLine();
Scanner input = new Scanner(System.in);
input.close();