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/

October 23, 2012

Java client server socket program example

Java networking program to get client ip address in server.


Description : The client tries to establish a connection to server having ip address 127.0.0.1 through port 6363. The socket class is used to establish connection . The server always listen to port 6363 for request from the clients. Once a request reach the server through that port, it establish a connection with that particular client. Multiple clients can connect to server, since i used thread in server.

October 14, 2012

Phone Number validation in java

Regular expression phone number validation in java

This example code is for phone number validation in java using regular expression and for internet protocol address validation in java


/**
 *
 * @author belazy
 * @version validates1.0
 */
public class Validator implements ValidaterInterface {


/**
 *
 * @see deeps
 * @param
 * @return boolean
 * Description : phone number validator
 * Date : Sep 19, 2007
 * Coded by : belazy
 */
public boolean phoneNumberValidator(String phoneNumber) {
        boolean isValid = false;
        String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$";
        CharSequence inputStr = phoneNumber;
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(inputStr);
        if (matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }

/**
 *
 * @see deeps
 * @param
 * @return boolean
 * Description : ip v4 validator
 * Date : Sep 19, 2007
 * Coded by : belazy
 */
public boolean ipaddressV4Validator(String ip) {
        String[] parts = ip.split("\\.");
        if (parts.length < 5) {
            for (String s : parts) {
                int i = Integer.parseInt(s);
                if (i < 0 || i > 255) {
                    return false;
                }
            }
        } else {
            return false;
        }
        return true;
    }


}



To trace the caller details in your java apps you can use true caller api

True caller API Documentation 


http://belazy.blog.com/

October 11, 2012

check or uncheck a html checkbox using jquery

How to check or uncheck a html checkbox using jquery.

How to select or choose a checkbox?

$('input:checkbox[value=Barcelona]').attr('checked',true);

The above code will check/choose/select a html checkbox whose value is hello, you can even choose name instead of value

$('input:checkbox[name=premierleague]').attr('checked',true);

to uncheck use the below code

$('input:checkbox[value=realMandrid]').attr('checked',false);

This is a small example for AJAX jquery checkbox example, please try it ....

http://belazy.blog.com/  +joseph james 

Facebook comments