Input/Output for lines of text
The first line contains the number of lines to follow, followed by that number of lines of text on STDIN. Output to STDOUT each line of input by passing it to a method as an intermediate step. The code should demonstrate these 3 things. See also Input/Output for Pairs of Numbers and File/Input and Output.
- Sample input with corresponding output
Input
3 hello hello world Pack my Box with 5 dozen liquor jugs
Output
hello hello world Pack my Box with 5 dozen liquor jugs
Java
<lang java>import java.util.Scanner;
public class Main { public static void doStuff(String word){ System.out.println(word); }
public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = Integer.parseInt(in.nextLine()); for(int i=0; i<n; i++){ String word = in.nextLine(); doStuff(word); } } }</lang>
Python
<lang python>def do_stuff(word): print(word)
t = input() for x in range(0, t): word = raw_input() do_stuff(word)</lang>
Ruby
<lang ruby>def do_stuff(word) puts word end
t = gets.to_i for i in 1..t do word = gets do_stuff(word) end</lang>