Java - Write code to Skip any spaces at or after start and returns the index of first non-space character;

Requirements

Write code to Skip any spaces at or after start and returns the index of first non-space character;

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com";
        int start = 42;
        System.out.println(skipSpaces(s, start));
    }//from   w  ww  .j  a  v  a2 s .co m

    /**
     * Skips any spaces at or after start and returns the index of first
     * non-space character;
     * @param s the string
     * @param start index to start
     * @return index of first non-space
     */
    public static int skipSpaces(String s, int start) {

        int limit = s.length();
        int i = start;

        for (; i < limit; i++) {
            if (s.charAt(i) != ' ') {
                break;
            }
        }

        return i;
    }
}