package pack1;
import java.util.Arrays;
import java.util.Scanner;
public class one {
void search(String str)
{
int len=str.length();
char arr[]=str.toCharArray();
int a[]=new int[len];
int index=0;
for(int i=0;i<len;i++)
{
index=str.indexOf(arr[i], i+1);
if(index==-1)
a[i]=999;
else
a[i]=index;
}
for(int i=0;i<len;i++)
{
System.out.print("--"+a[i]);
}
System.out.println("首次出现两次的字母是:");
Arrays.sort(a);
index=a[0];
if(index==999)
{
System.out.print("no one have double");
}
else
System.out.print(arr[a[0]]);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
one a=new one();
a.search("mdfss");
}
}
望批评指正
时间: 2024-10-14 02:56:00