May 29, 2017

input ab2c3 output ababcababcababc String manipulation

/**
 * input happ3ymarri4geanive6sa6y9
 */
/**
 * input ab2c3
 * output ababcababcababc
 */
package com.codecreeks.solutions;

/**
 * @author Steffi
 *
 */
public class StringManipBuffer {

/**
* @param args
*/
public static void main(String[] args) {

long startTime = System.currentTimeMillis();

StringManipBuffer stringManip = new StringManipBuffer();
String output = stringManip.compute("ab9c9");
System.out.println(output);
Runtime runtime = Runtime.getRuntime();
        runtime.gc();
        long memory = runtime.totalMemory() - runtime.freeMemory();
        System.out.println("Used memory is KB: " + memory/1024);
        long stopTime = System.currentTimeMillis();
        long elapsedTime = stopTime - startTime;
        System.out.println(" Time Taken :"+elapsedTime);

}

private String compute(String input) {
StringBuffer sb = new StringBuffer();
char[] charInput = input.toCharArray();
for (Character ch : charInput) {
if (ch.isDigit(ch)) {
String str = loop(sb.toString(), (int) ch - 48);
sb.delete(0,sb.length());
sb.append(str);
} else {
sb.append(ch);
}
}

return sb.toString();
}

private String loop(String str, int count) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < count; i++) {
sb.append(str);
}
return sb.toString();
}

}

/**
 * input ab2c3
 * output ababcababcababc
 */
package com.codecreeks.solutions;

/**
 * @author Steffi
 *
 */
public class StringManip {

/**
* @param args
*/
public static void main(String[] args) {

long startTime = System.currentTimeMillis();
StringManip stringManip = new StringManip();
String output = stringManip.compute("ab9c9");
System.out.println(output);
Runtime runtime = Runtime.getRuntime();
        runtime.gc();
        long memory = runtime.totalMemory() - runtime.freeMemory();
        System.out.println("Used memory is KB: " + memory/1024);
        long stopTime = System.currentTimeMillis();
        long elapsedTime = stopTime - startTime;
        System.out.println(" Time Taken :"+elapsedTime);
}

private String compute(String input) {
StringBuilder sb = null;
char[] charInput = input.toCharArray();
for (Character ch : charInput) {
if (ch.isDigit(ch)) {
String str = loop(sb.toString(), (int) ch - 48);
sb = new StringBuilder(str);
} else {
if (null == sb) {
sb = new StringBuilder();
sb.append(ch);
}
}

return sb.toString();
}

private String loop(String str, int count) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < count; i++) {
sb.append(str);
}
return sb.toString();
}

}

input ab2c3

ababcababcababc
Used memory is KB: 292
 Time Taken :6

ababcababcababc
Used memory is KB: 293
 Time Taken :8

input ab9c9

abababababababababcabababababababababcabababababababababcabababababababababcabababababababababcabababababababababcabababababababababcabababababababababcabababababababababc
Used memory is KB: 293
 Time Taken :7

abababababababababcabababababababababcabababababababababcabababababababababcabababababababababcabababababababababcabababababababababcabababababababababcabababababababababc
Used memory is KB: 293
 Time Taken :6

May 14, 2017

Java Technical Question in bayt.com

Ross is an event organizer. He has received data regarding the participation of employees in two different events ( say event One and event Two ). Some employees have participated in only one event and others have participated in both events. Ross now needs to count the number of employees who have taken part in both events. The record received by Ross consist of employee ids, which are unique. Write a program that accepts the employee ids participating in each event ( the first line relates to the first event and the second line relates to the second event). The program should print the number of common employee ids in both the events.

Suppose the following input is given to the program, where each line represents a different event.

1001,1002,1003,1004,1005
1106,1008,1005,1003,1016,1017,1112

Now the common employee ids are 1003 and 1005 so the program should give the output as:2

java source code

import java.util.ArrayList;
import java.util.List;

/**
 * solutions for question one
 */

/**
 * @author shimjith consumerfed
 *
 */
public class EventOrganizer {

private List<Integer> eventOne = null;
private List<Integer> eventTwo = null;
private static int count = 0;

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
EventOrganizer main = new EventOrganizer();
main.getEmployeeDetails();
main.showEmployeeDetails();
main.findEmployeeDetails();
System.out.println("The employee present in both events :"+EventOrganizer.count);

}

// to get employees present in both arrays
private void findEmployeeDetails() {
// TODO Auto-generated method stub
for (int row: eventOne){

if(eventTwo.contains(row)){
count = count +1;
}
}

}

private void showEmployeeDetails() {
// TODO Auto-generated method stub
System.out.println("Employee ids of event one "+eventOne);
System.out.println("Employee ids of event two "+eventTwo);
}

private void getEmployeeDetails() {
// You can use scanner class to get values to event one and two
eventOne = new ArrayList<Integer>();
eventTwo = new ArrayList<Integer>();
eventOne.add(1001);
eventOne.add(1002);
eventOne.add(1003);
eventOne.add(1004);
eventOne.add(1005);
eventTwo.add(1106);
eventTwo.add(1008);
eventTwo.add(1005);
eventTwo.add(1003);
eventTwo.add(1016);;
eventTwo.add(1017);
eventTwo.add(1112);

}

}


out put

May 13, 2017

Hadoop

http://javabelazy.blogspot.in/

May 02, 2017

'org.eclipse.jst.jee.server:your_apps_name' did not find a matching property error



'org.eclipse.jst.jee.server:your_apps_name' did not find a matching property error

These are not error , you just need to

check Publish module context on separate xml file

Option

after double clicking server

http://javabelazy.blogspot.in/

Facebook comments