r/javahelp•
Beastinabox997

Returning a substring without using .substring

I have a String and two int parameters, the starting index and and ending index. Currently my code only returns the final index but I am trying to return the substring between the start and end indexes.

public static String substringpractice(String x, int startIndex,int endIndex) {

    String b = "";

    for(int i = startIndex; i < endIndex;i++) {
        b = x.charAt(i) + "";
    }


    return b;

Posted Mar 12, 2018, 9:33 PM UTC

511
Loading comments…