White Spaces

Hello World
public class Test  {
    static char a[] = {'a',' ', 'b',' ','c',' ', ' ', ' ', 'd'};
    public static void displayNonWhiteSpaces() {
        for(int i=0; i<a.length; i++) {
            if(a[i] != ' ') {
                System.out.println(a[i]);
            }
        }
    }

    public static void removeWhiteSpaces() {
        int k=0;
        for(int i=0; i<a.length; i++) {
            if(a[i] != ' ') {
                a[k++] = a[i];
                if(k<i) {
                    a[i] = ' ';
                }
            }
        }

        System.out.println("Length " + a.length);

        for(int i=0; i<a.length; i++) {
            System.out.print("\n" + a[i]);
        }

    }

    public static void main(String args[]) {
        displayNonWhiteSpaces();
        removeWhiteSpaces();
    }
}

No comments:

Post a Comment

NoSQL

This one is reviewed but I need to delete its copy from hubpages or somewhere NoSQL Data models: key-value  Aggregate model.  key or i...