Last active
July 21, 2018 12:56
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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