Sunday, March 18, 2018

Write a program in java to find the 1st non repeated character from the string.



/*
WAP to find the 1st non repeated character from the string.
In this string ("altaf alam") 1st Non repeat character is 't'

*/


import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NonRepeatChar {

public static void main(String[] args) {

String s="altaf alam";
for(int i=0;i<s.length();i++)
{
Pattern p=Pattern.compile(String.valueOf(s.charAt(i)));
Matcher m=p.matcher(s);
m.find();
if(!(m.find()))
{
System.out.println("First Non repeatable Character = "+s.charAt(i));
break;
}
}
}
}





Java program in java to find the 1st non repeated character from the string.




Share this

0 Comment to "Write a program in java to find the 1st non repeated character from the string."

Post a Comment