gpt4 book ai didi

java - Id.CharAt() 的整数版本

转载 作者:行者123 更新时间:2023-12-03 01:27:26 25 4
gpt4 key购买 nike

我正在尝试创建一个包含该人出生年份的最后 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");
}

最佳答案

最后两位数字可以通过以下方式获得:

int lastTwo = byear % 100;

当然,如果您单独需要它们,则需要一些额外的工作:

int last = byear % 10;
int beforeLast = (byear/10) % 10;

关于java - Id.CharAt() 的整数版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50622864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com