// // Sentinel-ctrl loops // read words by words and stop when 'q' is read // assuming "q" is the sentinel import java.util.Scanner; class Prog_6_5m { public static void main(String[] args) { Scanner input = new Scanner(System.in); int count = 0; String data; data = input.next(); // priming read while ( !data.equalsIgnoreCase("q") ) // Not the sentinel? { System.out.print(data + " "); // output the words count ++; data = input.next(); // reading the next } System.out.println("size = " + count); } }