Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有一种java字符的方法可以按字典顺序返回下一个字符?
char x = 'a'.next();
'a'.next()会回来b的。'b'.next()会回来c的。等等
'a'.next()
b
'b'.next()
c
char x = 'a'; System.out.println(++x);
输出:b
我希望这足以作为一个提示。
基本上,只需增加char变量的 ASCII 码即可获得下一个字符。
char
是的,ASCII代码基本上只是一个整数。(尝试做System.out.println((int) 'a');,你会得到输出97,这是 char 的 ASCII 值a)。同样,每个字符都有一些 ASCII 值。
ASCII
System.out.println((int) 'a');
97
a