How do I increment a variable to the next or previous letter in the alphabet?
问题 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' . 回答1: One way: String value = "C"; int charValue = value.charAt(0); String next = String.valueOf( (char) (charValue + 1)); System.out.println(next); 回答2: Well if you mean the 'ABC' then they split into two sequences a-z and A-Z, the simplest way I think would be to use a char variable and