在java中如何用循环查找和删除重复的字符
展开全部
public static void main(String[] args) {
String str = "腊搜asgsadd";
removeDuplicate3(str);
}
//轮戚历去除重复字符仔羡
private static void removeDuplicate3(String s) {
if (s == null){
return;
}
if (s.length() < 2){
}
char[] ch = s.toCharArray();
int count =0;
int p = 0;
int len = s.length();
for (int i = 0; i < len; i++) {
if (ch[i] != ' ') {
for (int j = i + 1; j < len; j++)
if (ch[j] == ch[i]) {
ch[j] = ' ';
}
ch[p++] = ch[i];
System.out.print(ch[i]);
}
}
}
String str = "腊搜asgsadd";
removeDuplicate3(str);
}
//轮戚历去除重复字符仔羡
private static void removeDuplicate3(String s) {
if (s == null){
return;
}
if (s.length() < 2){
}
char[] ch = s.toCharArray();
int count =0;
int p = 0;
int len = s.length();
for (int i = 0; i < len; i++) {
if (ch[i] != ' ') {
for (int j = i + 1; j < len; j++)
if (ch[j] == ch[i]) {
ch[j] = ' ';
}
ch[p++] = ch[i];
System.out.print(ch[i]);
}
}
}
展开全部
class Main{
public static String rev(String str){
if(str.isEmpty()) return "";
char c=str.charAt(str.length()-1);
String last=str.substring(0,str.length()-1);
if(last.indexOf(c)==-1){
烂辩核 return rev(last)+c;
}else {
饥掘 return rev(last);
}
}
public static void main(String[] args){
灶晌 System.out.println(rev("abcqwebca"));
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询