随笔都是学习笔记
随笔仅供参考,为避免笔记中可能出现的错误误导他人,请勿转载。
package Demo_1_22_String;

public class StringDemo {
    public static void main(String[] args) {
        String str = "www.baidu.com";
        char c = str.charAt(4);      // charAt()获取索引所在的字符
        System.out.println("char c = " + c);

        //将str的字母变为大写
        // 将字符串变为字符数组
        char [] result = str.toCharArray();
        for (int i = 0; i < result.length; i++) {
            if (result[i] == '.') {
            }else {
                result[i] -= 32;    // 编码表的位置向前移动32位
            }
        }
        String newStr = new String(result);     // 将字符数组变为字符串
        System.out.println(newStr);

        char a = '1';
        System.out.println(a);
    }

}

 

posted on 2022-01-22 13:35  时间完全不够用啊  阅读(80)  评论(0编辑  收藏  举报