字符串取重:
1.用数组解决:例如
当j=3时,a重复那么将后面的元素向前移,然后再缩容数组。
public static void main(String[] args) {
demotext dt=new demotext();
dt.method();
}
public void method(){
System.out.println("输入一个字符串:");
Scanner sc=new Scanner(System.in);
String str=sc.next();
char[] arr={};
for (int i = 0; i
2.标志法:
例如:
a b c a b c b b,我们不妨再创建个数组,这个数组长度与上个数组长度相同,但内容全都为0.则 0 0 0 0 0 0 0 0.然后我们进行循环匹配,当a重复时,则使它对应的下标0数组为1.同理bc也一样。那么会是 a b c a b c b b
0 0 0 1 1 1 1 1
这时光输出0元素所对应的字符就达到取重效果。
//字符逐个输入给数组
System.out.println("输入一个字符串:");
Scanner sc=new Scanner(System.in);
String str=sc.next();
char[] arr={};
for (int i = 0; i



