Showing posts with label PowerballNumbers. Show all posts
Showing posts with label PowerballNumbers. Show all posts

January 29, 2013

Thread Enumerator Example

Java example to set condition in Thread 


package yahoofinance;

public class ThreadExamples implements Runnable {
   
    public enum Traffic { NORTH, SOUTH, EAST, WEST, NOTHING }
    static Traffic isOn = Traffic.NOTHING;
    @Override
    public void run() {
        while(true){
            switch (isOn) {
            case NORTH:
                System.out.println(" north is on ");
                break;
            case SOUTH:
                System.out.println(" south is on ");
                break;
            case EAST:
                System.out.println(" east is on ");
                break;
            case WEST:
                System.out.println(" west is on ");
                break;
            case NOTHING:
                System.out.println(" default is on ");
                break;
            default:
                System.out.println(" default is on ");
                break;
            }
        }
       
    }
   
    public static void main(String[] election) throws InterruptedException {
         ThreadExamples t = new ThreadExamples();
         Thread th = new Thread(t);
         th.start();
         th.sleep(5000);
         isOn = Traffic.NORTH;
         th.sleep(1000);
         isOn = Traffic.WEST;
    }

}

How to manipulate/control a running thread from another class.



http://belazy.blog.com/

October 24, 2012

Multunus Solution

Solution for multunus puzzle

:  http://www.multunus.com/careers#hiring-process-faq , http://puzzle.multunus.com/cloud/create
Main.java



import java.util.Map;
import java.util.Scanner;

public class Main {
   
    private String orginalString = "";
    private String duplicateString = "";
    private KeyValues keyvalues = null;
    private Map<String,String> mp = null;
   

   
    public static void main(String[] args) {
      
        Main  m = new Main();
        m.getUserInput();
      
    }

    private void getUserInput() {

        keyvalues = new KeyValues();
        mp=keyvalues.getValueMap();
   
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        orginalString = name;
        if(name.contains(" ")){
            String []strSpace = name.split(" ");
            for(String str : strSpace){
                //System.out.println(str);
                checkForZero(str);
            }
        }else{
            checkForZero(name);
        }
      
    }

    private void checkForZero(String stri) {
        if(stri.contains("0")){
            String [] strZero = stri.split("0");
            for(String st : strZero){
                    //System.out.println(st);
                    checkRedd(st);
                    System.out.print("\t");
            }
        } else{
            checkRedd(stri);
        }
      
    }

    private void checkRedd(String st) {
        int startpt =0;
        String tempStr = st;
        //System.out.println(tempStr.length());
        int i = 1;
        while(i < tempStr.length()){
            //System.out.println(tempStr.charAt(i));
            //System.out.println(tempStr.charAt(i-1)+"---"+tempStr.charAt(i));
            if(tempStr.charAt(i-1) != tempStr.charAt(i)){
                duplicateString = duplicateString + tempStr.substring(startpt,i);
                //System.out.println(tempStr.substring(startpt,i));
                System.out.print("#########"+mp.get(duplicateString));
                startpt = i;
            }
            else{
                duplicateString="";
            }
          
          
            i++;
        }
        System.out.print(" kate output "+mp.get(tempStr.substring(duplicateString.length(),tempStr.length())));
        //System.out.println(orginalString.substring(duplicateString.length(),orginalString.length()));
    }

}
KeyValues.java


import java.util.HashMap;
import java.util.Map;

/**
 *
 */

/**
 * @author Aromal *
 */
public class KeyValues {
   
    private Map<String,String> valueMap = null;
   

    public KeyValues(){
        valueMap = new HashMap<String, String>();
        addValues();
    }
   
   
    private void addValues() {
        valueMap.put("2", "a");
        valueMap.put("22", "b");
        valueMap.put("222", "c");
        valueMap.put("3", "d");
        valueMap.put("33", "e");
        valueMap.put("333", "f");
        valueMap.put("4", "g");
        valueMap.put("44", "h");
        valueMap.put("444", "i");
        valueMap.put("5", "j");
        valueMap.put("55", "k");
        valueMap.put("555", "l");
        valueMap.put("6", "m");
        valueMap.put("66", "n");
        valueMap.put("666", "o");
        valueMap.put("7", "p");
        valueMap.put("77", "q");
        valueMap.put("7777", "r");
        valueMap.put("8", "s");
        valueMap.put("88", "t");
        valueMap.put("888", "u");
        valueMap.put("9", "v");
        valueMap.put("99", "w");
        valueMap.put("999", "y");
        valueMap.put("9999", "z");
    }


    public Map<String, String> getValueMap() {
        return valueMap;
    }





}

Thanks +aromal chandra   and  +joseph james ...

http://belazy.blog.com/

Facebook comments