import java.util.Arrays; public class Javatest75 { /** *笔试题 * 练习1:删除字符串下标是3的倍数的字符 ,s = "aabbcdeefg",输出abcdef * [a, a, b, b, c, d, e, e, f, g] * abcdef */ public static void main(String[] args) { String s = "aabbcdeefg"; //将字符串转换成字符数组 char[] arr = s.toCharArray(); //打印字符数组 System.out.println(Arrays.toString(arr)); //遍历字符数组,将下标是3的倍数的字符替换成‘ ’ for (int i = 0; i < arr.length; i++) { if(i % 3 == 0){ arr[i] = ' '; } } StringBuilder s1 = new StringBuilder(); //遍历字符数组,将不是空格的字符按顺序一次添加至s1 for (int j = 0; j < arr.length; j++) { if(arr[j] == ' '){ continue; } s1.append(arr[j]); } //打印s1 System.out.println(s1.toString()); } }