Most HackerRank challenges require you to read input from stdin (standard input) and write output to stdout (standard output).
One popular way to read input from stdin is by using the Scanner class and specifying the Input Stream as System.in. For example:
Scannerscanner=newScanner(System.in);StringmyString=scanner.next();intmyInt=scanner.nextInt();scanner.close();System.out.println("myString is: "+myString);System.out.println("myInt is: "+myInt);
The code above creates a Scanner object named and uses it to read a String and an int. It then closes the Scanner object because there is no more input to read, and prints to stdout using System.out.println(String). So, if our input is:
In this challenge, you must read integers from stdin and then print them to stdout. Each integer must be printed on a new line. To make the problem a little easier, a portion of the code is provided for you in the editor below.
There are lines of input, and each line contains a single integer.