JP Morgan Interview Question for Java Developers


Country: India
Interview Type: Written Test




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

public class ClassA {

    public static void main(String[] args) {
        //input
        char[] str = "012345678".toCharArray();

        //reverse 
        for (int i = 0; i < str.length / 2; i++) {
            char a = str[i];
            str[i] = str[str.length - i - 1];
            str[str.length - i - 1] = a;
        }

        //output
        for (char c : str) {
            System.out.print(c);
        }

- mger1979 May 16, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

Well there are many implementations possible, but the coolest would be -

StringBuilder sb = new StringBuilder("word");
System.out.println(sb.reverse().toString());

- Flash May 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class code
{
String s;
public void revrese(String a)
{
s=a;
//char c= (Character) null;
int l=s.length();

for(int i=l-1;i>=0;i--)
{
char ch=s.charAt(i);
System.out.print(ch );
}
}
public static void main(String args[])
{
code c=new code();
c.revrese("visahl kumar");
}
}

- vishaldets May 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

To swap it in place:

public static String reverse(String s) {
	if (s == null) {
		return null;
	}

	final StringBuilder mutableString = new StringBuilder(s);

	int startIndex = 0;
	int endIndex = s.length();
	char c;
	while (startIndex < endIndex) {
		// Swap chars
		c = mutableString.charAt(endIndex);
		mutableString.setCharAt(endIndex, mutableString.charAt(startIndex));
		mutableString.setCharAt(startIndex, c);

		startIndex++;
		endIndex--;
	}

	return mutableString.toString();
}

- feistc May 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class TestAnything {


public static void main(String[] args) {

System.out.println(reverseString("Aything"));
}

public static String reverseString(String s){

String rs="";
if(s.length()==1){
return s;
}
String s1=s.substring(s.length()-1);
String s2=s.substring(0, s.length()-1);
return rs=s1+reverseString(s2);
}
}

- Rahul Lambat June 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class TestAnything {


public static void main(String[] args) {

System.out.println(reverseString("Aything"));
}

public static String reverseString(String s){

String rs="";
if(s.length()==1){
return s;
}
String s1=s.substring(s.length()-1);
String s2=s.substring(0, s.length()-1);
return rs=s1+reverseString(s2);
}
}

- Rahul Lambat June 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class TestAnything {public static void main(String[] args) {System.out.println(reverseString("Aything"));}
public static String reverseString(String s){String rs="";
if(s.length()==1){return s;}
String s1=s.substring(s.length()-1);
String s2=s.substring(0, s.length()-1);
return rs=s1+reverseString(s2);
}
}

- Rahul Lambat June 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class TestAnything {public static void main(String[] args) {System.out.println(reverseString("Aything"));}
public static String reverseString(String s){String rs=""; if(s.length()==1){return s;}
String s1=s.substring(s.length()-1);
String s2=s.substring(0, s.length()-1);
return rs=s1+reverseString(s2);
}
}

- Rahul Lambat June 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

test

- Rahul June 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class TestAnything {public static void main(String[] args) {System.out.println(reverseString("Aything"));}
public static String reverseString(String s){String rs="";
if(s.length()==1){return s;
}
String s1=s.substring(s.length()-1);
String s2=s.substring(0, s.length()-1);
return rs=s1+reverseString(s2);
}
}

- rahul.lambat June 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {


public static void main(String[] args) {


String str = "0123456789";
char arrayChar[] = str.toCharArray();
char reverseArray[] = new char[str.length()];


for(int i=str.length()-1,j=0;i>=0;i--,j++){
reverseArray[j]=arrayChar[i];

}

System.out.println(" reverse String "+new String(reverseArray));


}

}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {
public static void main(String[] args) {
String str = "0123456789";
char arrayChar[] = str.toCharArray();
char reverseArray[] = new char[str.length()];
for(int i=str.length()-1,j=0;i>=0;i--,j++){
reverseArray[j]=arrayChar[i];
}
System.out.println(" reverse String "+new String(reverseArray));
}
}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {
public static void main(String[] args) {
String str = "0123456789";
char arrayChar[] = str.toCharArray();
char reverseArray[] = new char[str.length()];
for(int i=str.length()-1,j=0;i>=0;i--,j++){
reverseArray[j]=arrayChar[i];
}
System.out.println(" reverse String "+new String(reverseArray));
}
}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {public static void main(String[] args){
String str = "0123456789";char arrayChar[] = str.toCharArray();char reverseArray[] = new char[str.length()];
for(int i=str.length()-1,j=0;i>=0;i--,j++){reverseArray[j]=arrayChar[i];}
System.out.println(" reverse String "+new String(reverseArray));}}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {
public static void main(String[] args) {

String str = "0123456789";

char arrayChar[] = str.toCharArray();

char reverseArray[] = new char[str.length()];

for(int i=str.length()-1,j=0;i>=0;i--,j++) {

reverseArray[j]=arrayChar[i];

}

System.out.println(" reverse String "+new String(reverseArray));

}
}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {
public static void main(String[] args) {

String str = "0123456789";

char arrayChar[] = str.toCharArray();

char reverseArray[] = new char[str.length()];

for(int i=str.length()-1,j=0;i>=0;i--,j++) {

reverseArray[j]=arrayChar[i];

}

System.out.println(" reverse String "+new String(reverseArray));

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String str = "0123456789";

char arrayChar[] = str.toCharArray();

char reverseArray[] = new char[str.length()];

for(int i=str.length()-1,j=0;i>=0;i--,j++) {

reverseArray[j]=arrayChar[i];

}

System.out.println(" reverse String "+new String(reverseArray));

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {
	public static void main(String[] args) {
		
		String str = "0123456789";
		
		char arrayChar[] = str.toCharArray();
		
		char reverseArray[] = new char[str.length()];
		
		for(int i=str.length()-1,j=0;i>=0;i--,j++) {
			
			reverseArray[j]=arrayChar[i];
			
			}
		
		System.out.println("  reverse String "+new String(reverseArray));
		
		} 
}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {
	public static void main(String[] args) {
		
		String str = "0123456789";
		
		char arrayChar[] = str.toCharArray();
		
		char reverseArray[] = new char[str.length()];
		
		for(int i=str.length()-1,j=0;i>=0;i--,j++) {
			
			reverseArray[j]=arrayChar[i];
			
			}
		
		System.out.println("  reverse String "+new String(reverseArray));
		
		} 
}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {

String str = "0123456789";

char arrayChar[] = str.toCharArray();

char reverseArray[] = new char[str.length()];

for(int i=str.length()-1,j=0;i>=0;i--,j++) {

reverseArray[j]=arrayChar[i];

}

System.out.println(" reverse String "+new String(reverseArray));

}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {
	public static void main(String[] args) {
		
		String str = "0123456789";
		
		char arrayChar[] = str.toCharArray();
		
		char reverseArray[] = new char[str.length()];
		
		for(int i=str.length()-1,j=0;i>=0;i--,j++) {
			
			reverseArray[j]=arrayChar[i];
			
			}
		
		System.out.println("  reverse String "+new String(reverseArray));
		
		} 
}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseString {
	public static void main(String[] args) {
		
		String str = "0123456789";
		
		char arrayChar[] = str.toCharArray();
		
		char reverseArray[] = new char[str.length()];
		
		for(int i=str.length()-1,j=0;i>=0;i--,j++) {
			
			reverseArray[j]=arrayChar[i];
			
			}
		
		System.out.println("  reverse String "+new String(reverseArray));
		
		}

}

- venkatacharan volleru June 20, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String result = null;
String str = "apple";
for (int i = (str.length - 1); i >= 0; i--) {
restult += str[i];
}
System.out.print(result);

- Anonymous March 30, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String result = null;
String str = "apple";
for (int i = (str.length - 1); i > 0; i--) {
  restult += str[i];
}
System.out.print(result);

- Anonymous March 30, 2018 | 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