-1

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.

Input Format

There are three lines of input:

-The first line contains an integer. -The second line contains a double. -The third line contains a String. Output Format

There are three lines of output:

-On the first line, print String: followed by the unaltered String read from stdin. -On the second line, print Double: followed by the unaltered double read from stdin. -On the third line, print Int: followed by the unaltered integer read from stdin.

Source Code

import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int i = scan.nextInt();
        double d = scan.nextDouble();
        String s = scan.nextLine();

        // Write your code here.

        System.out.println("String: " + s);
        System.out.println("Double: " + d);
        System.out.println("Int: " + i);
    }
}

Input

100
42

after inputting double it shows the ouput as follows

Output:

String: 
Double: 42.0
Int: 100
DanielBarbarian
  • 4,255
  • 12
  • 30
  • 38
  • https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo – achAmháin Jul 11 '19 at 14:28
  • I know I marked it as dup, but literally just add a line of `scan.nextLine();` after your `double d = scan.nextDouble();`. Its an easy fix. – Nexevis Jul 11 '19 at 14:32

0 Answers0