Hacker Rank: Java Three Different Variable

Problem 3 :-

In this challenge, you must read an integer, a double, and a String from stdin, then print the values according to the instructions in the Output Format section below. To make the problem a little easier, a portion of the code is provided for you in the editor.

Note: We recommend completing Java Stdin and Stdout I before attempting this challenge.

Input Format

There are three lines of input:
  1. The first line contains an integer.
  2. The second line contains a double.
  3. The third line contains a String.

Solution :-

import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int i = scanner.nextInt();

        double d = scanner.nextDouble();

        scanner.nextLine();

        String s = scanner.nextLine()

        System.out.println("String: " + s);

        System.out.println("Double: " + d);

        System.out.println("Int: " + i);

    }

}

Output :-

 

Post a Comment

Previous Post Next Post