Difference between revisions of "CSC212 Lab 6 Solutions 2014"

From dftwiki3
Jump to: navigation, search
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>

Revision as of 14:39, 1 October 2014

--D. Thiebaut (talk) 13:04, 1 October 2014 (EDT)




...