7
7 more points to get your first star!
Java Stdin and Stdout I Rank: 764701 | Points: 18/25
Java
Your Java Stdin and Stdout I submission got 5.00 points. Share Tweet
You are now 7 points away from the 1st star for your java badge.
Try the next challenge | Try a Random Challenge
Problem Submissions Leaderboard Editorial
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:
Scanner scanner = new Scanner(System.in);
String myString = scanner.next();
int myInt = 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:
Hi 5
Our code will print:
myString is: Hi
myInt is: 5
Alternatively, you can use the BufferedReader class.
Task
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.
Input Format
There are lines of input, and each line contains a single integer.
Sample Input
42
100
125
Sample Output
42
100
125
Change Theme Language Java 7
1 import java.util.*;
2
3 public class Solution {
4
5 public static void main(String[] args) {
6 Scanner sc = new Scanner(System.in);
7 for(int i=0;i<3;i++){
8 int a=sc.nextInt();
9 System.out.println(a);
10 }
11 }
12 }
13
Line: 6 Col: 19
Upload Code as File Test against custom input Run Code Submit Code
You have earned 5.00 points!
You are now 7 points away from the 1st star for your java badge.
72% 18/25
Congratulations Earn a certificate in Java
You solved this challenge. Would you like Kudos on your progress! Take the HackerRank
Next Challenge Get Certified
to challenge your friends? Skills Certification test and enrich your profile
Test case 0
Compiler Message
Success
Test case 1
Test case 2 Input (stdin) Download
1 42
2 100
3 125
Expected Output Download
1 42
2 100
3 125
Contest Calendar | Blog | Scoring | Environment | FAQ | About Us | Support | Careers | Terms Of Service | Privacy Policy | Request a Feature