首页 > 编程 > Java > 正文

Java Stdin and Stdout II

2019-11-06 07:05:02
字体:
来源:转载
供稿:网友

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); }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表