【发布时间】:2018-11-10 09:10:14
【问题描述】:
我正在尝试创建一个包含此人出生年份的最后 2 位数字的用户名,但它说不能取消引用 int。 id.charAt() 的 int 版本是什么?这是我的一段代码。
Scanner by = new Scanner (System.in);
System.out.println ("Please enter your birth year:");
int byear = by.nextInt();
if (byear >= 2008){
//the next 2 lines are what I'm having problems with:
char yeara = byear.charAt(2);
char yearb = byear.charAt(3);
//the 2 lines above ^^^
} else {
System.out.println ("Sorry, you're too young to use this website");
}
【问题讨论】:
-
请注意,如果您希望某人超过 10 岁(ish),则需要
byear <= 2008。否则,您将允许小于该年龄的人,并且消息应为too old to use this website。 -
我很惊讶我找不到这个的副本......这似乎很琐碎,以前一定有人问过......
-
@Sweeper 不确定你看起来有多努力...搜索“site:stackoverflow.com last two digits of int java”会显示很多结果。
-
@AndyTurner 啊我被标题骗了。我找不到关于 ints 的 charAt 方法的任何信息