本帖最后由 Yov正 于 2014-5-12 19:46 编辑
- import java.util.Scanner;
- /**
- * 输入字符串大小写转换
- *
- */
- class Test {
- public static void main(String[] args) throws Exception {
- Scanner cin = new Scanner(System.in);
- System.out.println("请输入字符串");
- String line = cin.next();
- System.out.println("转化大小写后 " + shiftCase(line));
- }
- private static String shiftCase(String line) {
- // TODO 自动生成的方法存根
- String shift = null;
- char[] chars = line.toCharArray();
- for (int i = 0; i < chars.length; i++) {
- if (chars[i] > 'a' || chars[i] < 'z') {
- chars[i] -= 32;
- } else if (chars[i] > 'A' || chars[i] < 'Z') {
- chars[i] += 32;
- }
- }
- shift=new String(chars);
- return shift;
- }
- }
复制代码 |
|