Saturday, June 13, 2015

Q.7 - Program to find out first non repeating character in a string.

public class FirstUnique{
public static void main(String args[]){
new FirstUnique().getUnique("stroirotatous");
}

public void getUnique(String str){
int arr[]  = new int[255];

for(int i = 0 ; i<str.length() ; i++)
{
arr[str.charAt(i)]++;
}

for(int j = 0; j<str.length(); j++)
{
if(arr[str.charAt(j)] == 1)
{
System.out.println((char)j);
return;
}
}

}
}

No comments:

Post a Comment