- package cn.itcast.rubby;
- public class KengDie
-
- //“helloWorld”大写变 小写,小写变大写
- {
- public static void main(String[] args) {
- String s="HelloWorld";
- //转数组
- char[] chs=s.toCharArray();
- StringBuffer sb=new StringBuffer();
- for (int i=0;i<chs.length;i++) {
- System.out.println(chs[i]);
- if (chs[i]>='A' && chs[i]<='Z') {
- //s.valueOf(chs[i])实现char转string
- String ss=s.valueOf(chs[i]).toLowerCase();
- //将ss装入StringBuffer sb中
- sb.append(ss);
- } else if(chs[i]>='a' && chs[i]<='Z'){
-
- String ss=s.valueOf(chs[i]).toUpperCase();
- sb.append(ss);
- }
-
- }
- System.out.println(sb);
- }
- }
复制代码 |
|