Answers for "how to reverse a 1st word in a string in java"

0

reverse sentence in java

// INPUT: "you shall not pass"
// OUTPUT: "pass not shall you"
  
String s[] = "you shall not pass".split(" "); 
String ans = ""; 
for (int i = s.length - 1; i >= 0; i--) {
  ans += s[i] + " ";
}
System.out.println(ans);
Posted by: Guest on March-06-2021
1

java reverse a word

To reverse a word 

- Put all the letters in a stack and pop them out. 
Because of the LIFO order of stack, you will get the letters in 
reverse order.
Posted by: Guest on October-13-2021
1

reverse a string in java

// Not the best way i know but i wanted to challenge myself to do it this way so :)
public static String reverse(String str) {
  char[] oldCharArray = str.toCharArray();
  char[] newCharArray= new char[oldCharArray.length];
  int currentChar = oldCharArray.length-1;
  for (char c : oldCharArray) {
    newCharArray[currentChar] = c;
    currentChar--;
  }
  return new String(newCharArray);
}
Posted by: Guest on February-11-2021

Code answers related to "how to reverse a 1st word in a string in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language