Java Stdin and Stdout II

编程知识 更新时间:2023-05-02 19:06:58

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).

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 empty = scan.nextLine();
        //this is the change to get the "enther key"
        String s = scan.nextLine();

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

更多推荐

Java Stdin and Stdout II

本文发布于:2023-04-28 04:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/f6cc0f86d4b2aa85100c4eeef7b59733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Stdin   Java   II   Stdout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 107694文章数
  • 27236阅读数
  • 0评论数