Wednesday, 27 June 2018

First Not Repeating Character



1. First Not Repeating Character

public class Simple{
public static void main(String args[]){

System.out.println("Result : "+firstNotRepeatingCharacter("abdecabde"));


}
public static char firstNotRepeatingCharacter(String s) {
    char[] c= s.toCharArray();
for(int i=0;i<s.length();i++){
    if(s.indexOf(c[i])==s.lastIndexOf(c[i]))
        return c[i];
}
    return '_';
}

}


2.  find century  from current year



int centuryFromYear(int year) {

     if (year % 100 == 0) {
            year = year / 100;
        } else {
            year = (year / 100) + 1;
        }
        return year;
}

No comments:

Post a Comment