Hello I am currently working on a program that reverses sentences using stacks. However, I need to implement a function that detects periods and then repeats the loop over again. For example, I could write "Hello my name is blank. nice to meet you." and it would print "you. meet to nice blank. is name my Hello" when I actually just need it to reverse each sentence individually, if that makes sense. So "blank is name my Hello. you meet to nice." is my desired output. Any advice would help greatly, thank you!
import java.util.Stack;
import java.util.Scanner;
public class NolascoStackReverse {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
Stack<String> reverse = new Stack<String>();
System.out.println("Enter a sentence to be reversed: ");
String str = in.nextLine();
String[] wordsArray = str.split(" ");
for (String word : wordsArray) {
reverse.push(word);
}
System.out.println("Here is the reversed order: ");
while (reverse.empty() == false) {
System.out.print(reverse.pop() + " ");
}
}
}