gpt4 book ai didi

java - 检测符号后的字符

转载 作者:行者123 更新时间:2023-12-01 15:50:44 25 4
gpt4 key购买 nike

我正在尝试以两种方式编写一个方法 - 如果符号 $ 之后的字符是整数,那么我想转到第二个 if 语句并执行它。如果符号 $ 后面的字符是数字(或字母),那么我想将该数字设置为 16,并且每次使用新数字时,我想将 setNumber 加 1。这是我尝试过的:

for (i=0; i<anyLines.length; i++) {

int setNumber = 16;

// 1st IF statement
if (Character.isDigit(anyLines[i].charAt(the character after $)))
anyLines[i] = anyLines[i].replace("$","");
anyLines[i] = anyLines[i].replace(charAt(after zero),setNumber);
// Increment set number if a new digit is detected

}

else {
continue;
}

// 2nd IF statement
if (anyLines[i].isInteger(anyLines[i].charAt(the character after $))) {
anyLines[i] = anyLines[i].replace("$","");
anyLines[i] = Integer.toBinaryString(131072
+(Integer.parseInt(anyLines[i]))).substring(1,17);
}
else {
continue;
}

我不知道该怎么做。

最佳答案

类似这样的事情:

public static void main(String[] args) {
String s = "af$Aklj$4r8$7jlkf$;a4$";
char[] cs = s.toCharArray();
for (int i = 0; i < cs.length; i++) {
if (cs[i] == '$') {
if (i + 1 < cs.length) {
i++;
if (Character.isDigit(cs[i])) {
System.out.print("digit after $: ");
} else if (Character.isLetter(cs[i])) {
System.out.print("letter after $: ");
} else {
System.out.print("unhandled character after $: ");
}
System.out.println(String.copyValueOf(cs, i-1, 2));
}
}
}
}

关于java - 检测符号后的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6105756/

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