String Reverse in Java...!

Answers were Sorted based on User's Feedback



String Reverse in Java...!..

Answer / shadow

//command line argument as string

public class StringReverse
{
public static void main(String[] args)
{
String string=args[0];
String reverse = new StringBuffer(string).reverse
().toString();


System.out.println("\nString before reverse:"+string);
System.out.println("String after reverse:"+reverse);
}
}


output:
C:\java\jdk>javac StringReverse.java
C:\java\jdk>java StringReverse "SHADOW"
String before reverse:SHADOW
String after reverse:WODAHS

Is This Answer Correct ?    8 Yes 2 No

String Reverse in Java...!..

Answer / soumya roy

public class rev
{

public static void main(String[] args)
{
String str="hi my name is hello ";
System.out.println("the string is :" + str);
char[] ch=str.toCharArray();
int i;
int len = ch.length;
for(i=len-1;i>=0;i--)
{
System.out.print(ch[i]);
}
}
}

Is This Answer Correct ?    3 Yes 1 No

String Reverse in Java...!..

Answer / anjani kumar jha

import java.util.*;

public class StringReverseWord {

private static void doStringReverseWord() {

String a = "Anjani ...................Kumar Jha";
Stack stack = new Stack();

// this statement will break the string into the
words which are separated by space.
StringTokenizer tempStringTokenizer = new
StringTokenizer(a);

// push all the words to the stack one by one
while (tempStringTokenizer.hasMoreTokens()) {
stack.push(tempStringTokenizer.nextElement());
}

System.out.println("\nOriginal string: " + a);

System.out.print("Reverse string: ");

//pop the words from the stack
while(!stack.empty()) {
System.out.print(stack.pop());
System.out.print(" ");
}
System.out.println("\n");
}
public static void main(String[] args) {
doStringReverseWord();

}

}

Is This Answer Correct ?    1 Yes 0 No

String Reverse in Java...!..

Answer / aravinda reddy

String reverse without using reverse method string class

public class StringReverse {
public static void main(String[] args) {
String str = "Aravind";
StringBuffer s = new StringBuffer();
char[] ch = str.toCharArray();
int n = ch.length;
for(int i=n-1;i>=0;i--)
s.append(ch[i]);
System.out.println(s.toString());
}
}

Is This Answer Correct ?    1 Yes 0 No

String Reverse in Java...!..

Answer / desai.ankita0422@gmail.com

yes

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

as we know a static method could access static data and static method only. then how could main method call the object of aclass which is not static and other non static data

1 Answers  


what is interface in java? Explain

0 Answers  


Does java support function overloading, pointers, structures, unions or linked lists?

0 Answers  


Can static method access instance variables ?

0 Answers  


What is passing parameters in java?

0 Answers  






Explain the overview of UDP messaging.

0 Answers  


What is classes in java?

0 Answers  


What is static block?

0 Answers  


What are the fileinputstream and fileoutputstream?

0 Answers  


Why do inner class cannot have static declaration except static nested class?

2 Answers   TCS, Wipro,


we know that every java prog must follows OOPS Principles. Anybody can answer, HOW THE FOLLOWING PROGRAM FOLLOWS OOPS CONCEPTS i.e, Inheritance,Polymarphism,Encapsulation? class a{ public static void main(String args[]){ System.out.println("Hello World"); } }

3 Answers  


Why does my function print none?

0 Answers  


Categories