Problem
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 Scanner 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
Sample Input
42 100 125
Sample Output
42 100 125
Java Stdin and Stdout I – Hacker Rank Solution
Code:
import java.util.*;
public class Solution
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
Disclaimer: The above Problem (Java Stdin and Stdout I ) is generated by Hackerrank but the Solution is Provided by MultiplexCoder. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website fill the following contact form thank you.
ConversionConversion EmoticonEmoticon