java - Display array of words in reverse order -


i have of code done not know how display sentence in reverse order entered. example; if 1 enters "my name joe" should display in output: joe name my

 import java.util.scanner;    public class sentence {      public static void main(string [] args) {          scanner input = new scanner(system.in);          system.out.print("enter sentence: ");          string sentence = input.nextline();           string[] words = sentence.split(" ");           // display array of words in           // reverse order      }  } 

if understand problem, can that:

public static void main(string [] args) {     scanner input = new scanner(system.in);     system.out.print("enter sentence: ");     string sentence = input.nextline();     string[] words = sentence.split(" ");     (int = words.length - 1; >= 0; i--) {         system.out.println(words[i]);     } } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -