Wednesday, 15 July 2015

Java Programs Made Easy

package Good.com;

import java.util.ArrayList;

public class Prog23 {
      static int op;

      public static void abc(String str) {
            ArrayList<Character> al = new ArrayList<Character>();
            ArrayList<Character> al1 = new ArrayList<Character>();
            int i, j, count = 0;
            for (i = 0; i < str.length(); i++) {
                  if (str.charAt(i) != ' ') {
                        al.add(str.charAt(i));
                  }
            }
            for (i = 0; i < al.size(); i++) {
                  count = 0;
                  if (al.get(i) != '*') {
                        for (j = i + 1; j < al.size(); j++) {
                              if (al.get(i) == al.get(j)) {
                                    al.set(j, '*');
                                    count++;
                              }
                        }
                        if (count == 0)
                              al1.add(al.get(i));
                  }
            }
            op = al1.size();

      }

      public static void main(String[] args) {
            String str = "Hello World";
            abc(str);
            System.out.println(op);
      }


}