[HackerRank Solutions] [Java] Introduction – Java Stdin and Stdout 2

Problem Statement

Most of the problems on HackerRank require reading input from stdin (standard input) and writing output to stdout (standard output).

One way to read from stdin is by using the Scanner class and specifying the InputStream as System.in. Alternatively, you can use the BufferedReader class.

Lines of output can be written to stdout with the System.out.println function.

For this exercise, you need to read inputs from stdin and print them to stdout.

Input Format

There are three lines of input.
Line one contains an integer.
Line two contains a double.
Line three contains a String.

Output Format

On the first line, print String: followed by the unaltered input String.
On the second line, print Double: followed by the unaltered input double.
On the third line, print Int: followed by the unaltered input integer.

To make the problem easier, a portion of the code is already provided in the editor.

Note: If you use the nextLine() method immediately following the nextInt() method, recall that nextInt() reads integer tokens; because of this, the last newline character for that line of integer input is still queued in the input buffer and the next nextLine() will be reading the remainder of the integer line (which is empty).

Sample Input

Sample Output


Note: Do not concern yourself with formatting the output at this time; the goal here is to acquaint yourself with stdin and stdout.


Solution

Note:

  • Solusi-solusi dari challenge yang diberikan HackerRank murni berasal dari penulis sendiri.
  • Bahasa pemrograman yang digunakan penulis untuk menyelesaikan challenge adalah Java.

 

Seperti pada challenge sebelumnya (Java Stdin and Stdout 1), pada challenge kali ini kita ditantang untuk menyelesaikan masalah tentang input-output. Jika sebelumnya input yang diminta hanya berupa bilangan integer, kali ini input-an lebih bervariasi, yaitu berupa tipe data integer, double, dan string.

Input-an dibagi ke dalam tiga baris dimana baris pertama berupa integer, baris kedua berupa double, dan baris ketiga berupa string. Untuk output-nya, pada baris pertama dicetak String: diikuti dengan string yang dimasukkan, baris kedua dicetak Double: diikuti dengan double yang dimasukkan, dan pada baris ketiga dicetak Int: diikuti dengan integer yang dimasukkan.

Erik Gunawan

Java Developer, Android Developer, Microsoft Office Specialist, Pengamat One Piece, Blogger, Mahasiswa

Erik Gunawan

Java Developer, Android Developer, Microsoft Office Specialist, Pengamat One Piece, Blogger, Mahasiswa

Leave a Reply

Your email address will not be published. Required fields are marked *

wp-puzzle.com logo