How to implement the C strrchr() function in Java

1 Answer

0 votes
public class Program {
    public static String strRChr(String stringToSearch, char charToFind) {
		int index = stringToSearch.lastIndexOf(charToFind);
		
		if (index > -1)
			return stringToSearch.substring(index);
		else
			return null;
	}
    
    public static void main(String args[]) {
        String str = "java programing";
        char ch = 'a';
        
        System.out.println(strRChr(str, ch));
    }
}


  
/*
run:
  
aming
  
*/

 



answered Mar 1, 2024 by avibootz

Related questions

1 answer 103 views
103 views asked Dec 19, 2022 by avibootz
1 answer 174 views
1 answer 135 views
1 answer 161 views
...