package tutorial;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;

public class bucky {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		System.out.println(Integer.bitCount(x1));
		String s = "buckey robertkrsv fsgfg";
		System.out.println(s.indexOf('k', 5)); // found the first index of k
		// count over the 5 elem
		System.out.println(s.indexOf('l'));
		System.out.println(s.indexOf("rob"));
		String a = "bacon ";
		String b = "    monster   ";
		System.out.println(a + b);
		System.out.println(a.concat(b));
		System.out.println(a.replace('b', 'f'));
		System.out.println(b.toUpperCase());
		System.out.println(b.trim());
		System.out.println(fact(5));

		String[] things = { "laser", "pie", "eggs", "hats" };
		List<String> list = new ArrayList<String>();

		// add array items to the list\
		for (String x : things) {
			list.add(x);
		}
		for (String x : list) {
			System.out.println(x);
		}
		String[] morethings = { "pie", "eggs", "rebeca" };
		List<String> list2 = new ArrayList<String>();
		for (String y : morethings) {
			list2.add(y);
		}
		for (int i = 0; i < list.size(); i++) {
			System.out.printf("%s ", list.get(i));
		}
		editlist(list, list2);
		System.out.println();
		for (int i = 0; i < list.size(); i++) {
			System.out.printf("%s ", list.get(i));
		}
		String[] thins = { "apples", "noobs", "pwnge", "bacon" };
		List<String> list1 = new LinkedList<String>();
		for (String x : thins) {
			list1.add(x);
		}
		String[] tns2 = { "bacon", "sausage", "goats", "harrypotter" };
		List<String> lst2 = new LinkedList<String>();
		for (String y : tns2) {
			lst2.add(y);
		}
		list1.addAll(lst2);
		lst2 = null;
		System.out.println();
		printMe(list1);
		System.out.println();
		removeStuff(list1, 0, 3);
		printMe(list1);
		reverseMe(list1);// reverse averything and print it out

		String[] stuff = { "babies", " watermelon", "melons" };
		LinkedList<String> thelist = new LinkedList<String>(
				Arrays.asList(stuff));

		thelist.add("pumking");
		thelist.addFirst("firstthing");
		thelist.addLast("me");
		// convert back to an array
		stuff = thelist.toArray(new String[thelist.size()]);
		for (String r : stuff) {
			System.out.printf("%s ", r);
		}
		String[] crap = { "apples", "lemons", "geese", "bacon", "youtube" };
		List<String> l1 = Arrays.asList(crap);

		Collections.sort(l1); // in alphabetical order
		System.out.println( l1); // entire list as a string

		Collections.sort(l1, Collections.reverseOrder()); // what do yuo want to
															// sort and how do
															// you want to sort
		System.out.println(l1);//ciudat face println only after 
		//create an array and convert to list
		Character[] ray = {'p','w','n'};
		List<Character> l = Arrays.asList(ray);
		System.out.println("List is : ");
		output(l); //method to be created
		
		///reverse and printout the list
		Collections.reverse(l); //reverse reverse everyting
		System.out.println("After reverse: ");
		output(l);
		
		//copy of a list
		//create a new array and a new list
		Character[] newRAY = new Character[l.size()];
		List<Character> lcopy = Arrays.asList(newRAY);
		Collections.copy(lcopy, l);
		System.out.println("copy of list: ");
		output(lcopy);
		
		//fill collections with crap
		Collections.fill(l, 'x');
		System.out.println("After filling the list! ");
		
		
		
	}
	private static void output(List<Character> lcopy) {
		// TODO Auto-generated method stub
		
	}
	

	public static void printMe(List<String> l) {
		for (String b : l) {
			System.out.printf("%s ", b);
		}
	}

	public static void removeStuff(List<String> l, int from, int to) {
		l.subList(from, to).clear();

	}

	public static void reverseMe(List<String> l) {
		ListIterator<String> bob = l.listIterator(l.size());
		System.out.println();
		while (bob.hasPrevious()) {
			System.out.printf("%s ", bob.previous());
		}
	}

	public static void editlist(Collection<String> l1, Collection<String> l2) {
		Iterator<String> it = l1.iterator();
		while (it.hasNext()) {
			if (l2.contains(it.next()))
				it.remove();
		}
	}

	/**
	 * recursion /* a method that calls itself /* ex factorial
	 */
	public static long fact(long n) {
		if (n <= 1) // base case
			return 1;
		else
			return n * fact(n - 1);
	}

}