如何将变量增加到字母表中的下一个或上一个字母? [英] How do I increment a variable to the next or previous letter in the alphabet?
本文介绍了如何将变量增加到字母表中的下一个或上一个字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在变量字符串中定义了大写字母,我想输出字母表中的下一个和前一个字母。例如,如果变量等于'C'
,我想输出'B'
和 'd'
。
I have a capital letter defined in a variable string, and I want to output the next and previous letters in the alphabet. For example, if the variable was equal to 'C'
, I would want to output 'B'
and 'D'
.
推荐答案
单程:
String value = "C";
int charValue = value.charAt(0);
String next = String.valueOf( (char) (charValue + 1));
System.out.println(next);
这篇关于如何将变量增加到字母表中的下一个或上一个字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文