Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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.
Comment

reverse words in a string java

// Java Program to reverse a String
// without using inbuilt String function
import java.util.regex.Pattern;
public class Exp {
 
    // Method to reverse words of a String
    static String reverseWords(String str)
    {
 
        // Specifying the pattern to be searched
        Pattern pattern = Pattern.compile("s");
 
        // splitting String str with a pattern
        // (i.e )splitting the string whenever their
        // is whitespace and store in temp array.
        String[] temp = pattern.split(str);
        String result = "";
 
        // Iterate over the temp array and store
        // the string in reverse order.
        for (int i = 0; i < temp.length; i++) {
            if (i == temp.length - 1)
                result = temp[i] + result;
            else
                result = " " + temp[i] + result;
        }
        return result;
    }
 
    // Driver methods to test above method
    public static void main(String[] args)
    {
        String s1 = "Welcome to geeksforgeeks";
        System.out.println(reverseWords(s1));
 
        String s2 = "I love Java Programming";
        System.out.println(reverseWords(s2));
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: como limitar o random em java 
Java :: OCA Exam Questions 
Java :: Zooming an Image using OpenCV in Java 
Java :: android diagonal gradle 
Java :: dna exercise 
Java :: Creating strings using the new keyword Java 
Java :: Java Protected Access Modifier package two 
Java :: intList 
Java :: Add space to the left and right sides of a cell 
Java :: jwt token in android studio 
Java :: hwo to calculate cuberoot of numbers in java 
Java :: min,max functions in java 
Java :: scanner in = new scanner(system.in) meaning in java 
Java :: Add Future Date in AndroidStudio 
Java :: how to add 0 in left padding using regular expression java 
Java :: tipe data c++ 
Java :: java find nth largest element using priority queue heap 
Java :: what singleton java spring 
Java :: zebra zpl print java 
Java :: opencv copy image java 
Java :: java create a random number 
Java :: a java program must have at least one of these: 
Java :: program to calculate and return the sum of distance between the adjacent numbers in an array of positive integer java 
Java :: reading data from wsdl in java 
Java :: io fole scanner object syntax 
Java :: deps-jar 
Java :: java switch case enum 
Java :: centrar valores en celda jtable java netbeans 
Java :: Java socket connect to gmail 
Java :: how to secure specific url in spring security 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =