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
- 首次使用:
- 因此,紧接着,通过以下方式使用换行符:
- 还要确保扫描仪已声明为
- 不要忘记在程序结束时关闭扫描仪
这回答了你的问题吗?不,我的代码没有将userMonth变成一个对象,当我稍后尝试引用它时,它没有连接到变量。请发布完整的代码。您是否使用
userMonth
int userMonth = 0; // initialize variable.
userMonth = input.nextInt();
input.nextLine();
Scanner input = new Scanner(System.in);
input.close();