Difference between revisions of "CSC212 Lab 6 Solutions 2014"
Line 155: | Line 155: | ||
</source> | </source> | ||
+ | <br /> | ||
+ | =Problem 4= | ||
+ | <br /> | ||
+ | <source lang="java"> | ||
+ | /** | ||
+ | * A word scanner. | ||
+ | * @author D. Thiebaut | ||
+ | */ | ||
+ | import java.util.Scanner; | ||
+ | import java.util.Stack; | ||
+ | |||
+ | public class Lab6_4 { | ||
+ | |||
+ | /** | ||
+ | * main entry point | ||
+ | * @param args | ||
+ | */ | ||
+ | public static void main( String[] args ) { | ||
+ | Scanner inputScanner = new Scanner( System.in ); | ||
+ | Stack stack = new Stack(); | ||
+ | |||
+ | while ( inputScanner.hasNextLine() ) { | ||
+ | String line = inputScanner.nextLine(); | ||
+ | System.out.println( line ); | ||
+ | Scanner wordScanner = new Scanner( line ); | ||
+ | |||
+ | while ( wordScanner.hasNext() ) | ||
+ | stack.push( (String) wordScanner.next() ); | ||
+ | |||
+ | |||
+ | while ( !stack.isEmpty() ) | ||
+ | System.out.print( (String) stack.pop() + " "); | ||
+ | |||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </source> | ||
+ | |||
<br /> | <br /> | ||
</onlydft> | </onlydft> |