Interview Question for Developer Program Engineers


Team: 1
Country: India
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SubString {

	public String subString(String s,int start,int end){
		if(start <0 || end<0 || start >=s.length() || end>=s.length()) return null;
		StringBuffer sb=new StringBuffer();
		for(int i=start;i<end;i++){
			sb.append(s.charAt(i));
		}
		return sb.toString();
	}
	public static void main(String[] args) {
		SubString t=new SubString();
		System.out.println(t.subString("Hello World", 0, 4));
		System.out.println(t.subString("Hello World", 2, 7));
		System.out.println(t.subString("Hello World", 0, 20));
	}

}

- Nikhil June 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String substring(String str, int start, int end){
    if(str == null){
        throw new NullPointerException();
    }
    if(end >= str.length() || start > end){
        throw new IllegalArgumentException();
    }
    StringBuilder substring = new StringBuilder();
    for(int i = start; i < end; i++){
        substring.append(str.charAt(i));
    }
    return substring.toString();
}

- zortlord June 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SubString {

	public static void main(String[] args){
		String a ="SampleProgram";
		int start = 0;
		int end = 6;
		StringBuilder sub = new StringBuilder();
		char[] ch = a.toCharArray();
		for(int i=0;i<ch.length;i++){
			if(end == i)
				break;
				sub = sub.append(Character.toString(ch[i]));
			
		}
		System.out.println(sub);
				
	}
}

- Anonymous June 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SubString {

	public static void main(String[] args){
		String a ="SampleProgram";
		int start = 0;
		int end = 6;
		StringBuilder sub = new StringBuilder();
		char[] ch = a.toCharArray();
		for(int i=0;i<ch.length;i++){
			if(end == i)
				break;
				sub = sub.append(Character.toString(ch[i]));
			
		}
		System.out.println(sub);
				
	}
}

- umamahes June 13, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;

public class SubString {

	static String getSubString(String str, int startIndex, int endIndex) {

		if (str == null) {
			throw new NullPointerException();
		}

		if (endIndex > str.length() || startIndex < 0 || startIndex > endIndex) {
			throw new IllegalArgumentException();
		}

		StringBuilder subString = new StringBuilder();
		for (int i = startIndex; i < endIndex; i++) {
			subString.append(str.charAt(i));
		}
		return subString.toString();
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String str;
		System.out.print("Enter String : ");
		str = sc.next();
		int startIndex, endIndex;
		System.out.print("Enter start index : ");
		startIndex = sc.nextInt();
		System.out.print("Enter end index : ");
		endIndex = sc.nextInt();
		System.out.println("Sub String : "
				+ getSubString(str, startIndex, endIndex));
		sc.close();
	}

}

- jp June 16, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class String1{
public static String subString(String str,int spos,int epos)
{
char[] c=str.toCharArray();
String str1='';
for(int i=spos;i<=epos;i++)
{
str1=str1+c[i];
}
return str1;
}
class Test{
public static void main(String[] args)
{
String str=new String("Vamsi Krishna");
System.out.println(String1.subString(str,2,6));
}
}

- Vamsi Krishna Mandalapu June 25, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
String str = "Hello world";
int from = 0;
int to = 6;
StringBuffer buffer = new StringBuffer();
if (to < str.length()) {
for (int i = from; i < to; i++) {
buffer.append(str.charAt(i));

}
} else {
System.out.println(" oops !! out of index ");
}
System.out.println(" " + buffer.toString());

}

- Apurva July 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
String str = "Hello world";
int from = 0;
int to = 6;
StringBuffer buffer = new StringBuffer();
if (to < str.length()) {
for (int i = from; i < to; i++) {
buffer.append(str.charAt(i));
}
} else {
System.out.println(" oops !! out of index ");
}
System.out.println(" " + buffer.toString());
}

- Apurva July 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SubString {

public static void main(String[] args) {
String a = "UniqueT";
int start = 1;
int end = 4;
char[] ch = a.toCharArray();
if (start >= 0 && start < a.length() && end < a.length()
&& end >= start) {
for (int i = start; i <= end; i++)
System.out.print(ch[i]);
}

}
}

- UniqueT July 07, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SubString {

public static String getSubString(String string,int start,int end)
{
String temp="";

if(start<end)
{
char ch=' ';
for(int i=start;i<=end;i++)
{
temp=temp+string.charAt(i);
}
}
else{
temp="End index should be less than start index";
}
return temp;
}
public static void main(String[] args)
{
System.out.println(getSubString("12345", 0, 4));
System.out.println(getSubString("12345", 2, 4));
System.out.println(getSubString("12345", 4, 4));
System.out.println(getSubString("12345", 4, 3));
}
}

- Abhimanyu Chopra July 24, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class CCSubStringDemo {

	public static void main(String[] args){
		String str="SampleProgramme";
		int start=0;
		int end=6;
		StringBuffer sb=new StringBuffer(str);
	char array[]=new char[6];
	
	sb.getChars(start,end,array,0);
      
	  for(int i=0;i<array.length;i++){
		
		 System.out.print(array[i]);
	  }
	 
				
	}
}

- reenakandari.14 January 24, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More