Java Stdin and Stdout I

  • + 0 comments

    import java.io.*;

    public class Main { public static void main(String[] args) throws IOException { // Create a BufferedReader to read from stdin BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        // Read the number of integers
        int n = Integer.parseInt(reader.readLine());  // Read the first line and convert it to an integer
    
        // Loop to read and print each integer
        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(reader.readLine());  // Read each integer and parse it
            System.out.println(num);  // Print the integer on a new line
        }
    
        // Close the reader
        reader.close();
    }
    

    }