我正在迭代这个循环。除了两个没有整数的点外,我需要在每个位置检查一个整数。我正在尝试想出跳过这些索引点的最佳方法。
for(int i = 0;i < 11;i++) {
if(!Character.isDigit(number.charAt(i))){
throw new SocSecException("At index "+i+" you should have a int ");
}
}
我试图在建议中包含一个额外的 if 语句
if(i == 3 && i == 6 i++)
希望跳过 3 和 6 索引,但它并没有在检查中的任何地方抛出错误。
如何排除 3 索引和 6 索引在该语句中抛出错误?
最佳答案
只需将条件放在 if 条件中并结合 and 运算符即可。
for(int i = 0;i < 11;i++) {
if(i!=3 && i!=6 && !Character.isDigit(number.charAt(i))){
throw new SocSecException("At index "+i+" you should have a int ");
}
}
关于java - 遍历循环并跳过 Java 中的特定索引点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36637569/