关于scanner的简单问题。
问题简单,请看注释。
import java.util.*;public class Test2 { private int a; private long b; private float c; private double d; private String e; private String scanner; Test2(String s){ scanner = s; } public static void main(String[] args){ Test2 test2 = new Test2("myString\n10\n20\n30.123\n" + "40.123\nMyString"); Scanner sc = new Scanner(test2.scanner); test2.e = sc.nextLine();//System.out.println(test2.e + ""); test2.a = sc.nextInt(); test2.b = sc.nextLong(); test2.c = sc.nextFloat(); test2.d = sc.nextDouble(); test2.e = sc.next(); //如果这换成 sc.nextLine()的话将什么都没有 这是为什么呢? System.out.println("a = " + test2.a + ", b = " + test2.b + ", c = " + test2.c + ", d = " + test2.d + ", e = " + test2.e + "."); }}