Skip to content

Instantly share code, notes, and snippets.

@micahstairs
Last active July 21, 2018 12:56
Show Gist options
  • Save micahstairs/4621124b499c38d064e3 to your computer and use it in GitHub Desktop.
Save micahstairs/4621124b499c38d064e3 to your computer and use it in GitHub Desktop.
Solution for String Manipulation 1 [Programming Competition Problems] (https://www.youtube.com/watch?v=LURXsBIoSqI)
import java.util.*;
public class ReverseWords {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int nLines = Integer.valueOf(sc.nextLine());
for (int i = 1; i <= nLines; i++) {
String line = sc.nextLine();
String[] words = line.split(" ");
String reversedLine = "";
for (int j = words.length - 1; j >= 0; j--) {
reversedLine += " " + words[j];
}
System.out.println("Case #" + i + ":" + reversedLine);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment