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