Answers for "string reversal in java"

14

how to reverse a string in java

public class ReverseString {
    public static void main(String[] args) {
        String s1 = "neelendra";
        for(int i=s1.length()-1;i>=0;i--)
            {
                System.out.print(s1.charAt(i));
            }
    }
}
Posted by: Guest on March-14-2020
2

java string reverse

String str = "Reverse this strings";
//for loop
for (int i = str.length() - 1; i >= 0; i--) {
	System.out.print(str.charAt(i));
}

// StringBuffer for multi thread
StringBuffer sb = new StringBuffer(); 
sb.append(str);
System.out.print(sb.reverse().toString());

// StringBuffer for single thread
StringBuilder sb = new StringBuilder(); 
sb.append(str);
System.out.print(sb.reverse().toString());
Posted by: Guest on June-01-2020
7

string reverse in java

String str = "Hello";
String reverse(String str){
  StringBuilder sb = new StringBuilder();
  sb.append(str);
  sb.reverse();
  return sb.toString();
}
Posted by: Guest on May-09-2020
0

String reverse in java

1)
String str = "Hello";
String result = "";

  for(int i = str.length()-1; i>=0; i--){
     result += str.charAt(i); // first solution, charAt method
 //  result += str1.substring(i, i+1); // first solution,  substring method
   }
   System.out.println(result);
}
Posted by: Guest on June-04-2021
0

reverse a string in java

public class Main {

    public static void main(String[] args) {
	// Write a Java program to reverse a string.
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the String:");
        char[] letters = input.nextLine().toCharArray();
        System.out.println(" Reverse String");
        for(int i = letters.length -1; i >= 0; i--){
            System.out.print(letters[i]);
        }
    }
}
Posted by: Guest on January-05-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language